This commit is contained in:
newtbot
2024-01-04 15:32:46 +08:00
parent db1b513ad5
commit 1819956bd0
21 changed files with 1541 additions and 642 deletions

View File

@ -6,7 +6,7 @@ const {
updateSensor,
deleteSensor,
getSensorById
} = require("../functions/APIDatabase.js");
} = require("../functions/apiDatabase.js");
const express = require("express");
const router = express.Router();
@ -14,7 +14,7 @@ const router = express.Router();
router.get("/", async (req, res, next) => {
try {
const sensor = await getSensor();
res.json(sensor);
res.status(200).json(sensor);
} catch (error) {
console.error(error);
next(error);
@ -25,6 +25,7 @@ router.post("/new", async (req, res, next) => {
try {
const { sensorname, added_by, mac_address , description, location } = req.body;
await addSensor(sensorname, added_by, mac_address ,description, location);
res.sendStatus(200)
} catch (error) {
console.error(error);
next(error);
@ -35,6 +36,7 @@ router.put("/update", async (req, res, next) => {
try {
const { id, sensorname, added_by, mac_address ,description, location } = req.body;
await updateSensor(id, sensorname, added_by, mac_address , description, location);
res.status(200).json({ message: "Sensor " + id + " updated" });
} catch (error) {
console.error(error);
next(error);
@ -45,6 +47,7 @@ router.delete("/delete", async (req, res, next) => {
try {
const { id } = req.body;
await deleteSensor(id);
res.status(200).json({ message: "Sensor " + id + " deleted" });
} catch (error) {
console.error(error);
next(error);
@ -54,7 +57,8 @@ router.delete("/delete", async (req, res, next) => {
router.get("/:id", async (req, res, next) => {
try {
const sensor = await getSensorById(req.params.id);
res.json(sensor);
res.status(200).json(sensor);
} catch (error) {
console.error(error);
next(error);