Add routes to get location and sensor by name
Added viewdata using chart.js
This commit is contained in:
@ -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
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user