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