Add routes to get location and sensor by name

Added viewdata using chart.js
This commit is contained in:
newtbot
2024-01-29 00:44:10 +08:00
parent fadabf3451
commit c268e1d33d
7 changed files with 264 additions and 151 deletions

View File

@ -3,6 +3,7 @@ const {
addSensor,
updateSensor,
deleteSensor,
getSensorByName,
getSensorById
} = require("../functions/sensor.js");
@ -52,6 +53,16 @@ router.delete("/delete", async (req, res, next) => {
next(error);
}
});
router.get("/name/:name", async (req, res, next) => {
try {
const sensor = await getSensorByName(req.params.name);
res.status(200).json(sensor);
} catch (error) {
console.error(error);
next(error);
}
});
router.get("/:id", async (req, res, next) => {
try {
const sensor = await getSensorById(req.params.id);