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

@ -2,6 +2,7 @@ const {
addLocation,
getLocation,
getLocationById,
getLocationByName,
updateLocation,
deleteLocation,
} = require("../functions/location");
@ -58,6 +59,19 @@ router.delete("/delete", async (req, res, next) => {
}
});
//get location by name
router.get("/name/:name", async (req, res, next) => {
try {
//get params
const { name } = req.params;
const location = await getLocationByName(name);
res.status(200).json(location);
} catch (error) {
console.error(error);
next(error);
}
});
//get location by id

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);