more routes!

This commit is contained in:
newtbot
2024-01-07 04:15:22 +08:00
parent 5ff05a7a9e
commit 64e022e2ea
3 changed files with 357 additions and 213 deletions

View File

@ -6,6 +6,7 @@ const {
updateSensorData,
deleteSensorData,
getSensorDataById,
getData,
} = require("../functions/apiDatabase.js");
@ -56,6 +57,42 @@ router.delete("/delete", async (req, res, next) => {
}
});
router.get("/data", async (req, res, next) => {
try {
let query = {
//can be desc or asc
order: req.query.order,
// number of data to be returned
limit: req.query.limit,
//can be sensorid, locationid
sensorid: req.query.sensorid,
//can be sensorid, locationid
locationid: req.query.locationid,
//yearly
year: req.query.year,
//monthly
month: req.query.month,
//weekly
week: req.query.week,
};
const data = await getData(query);
res.status(200).json(data);
} catch (error) {
console.error(error);
next(error);
}
});
router.get("/:id", async (req, res, next) => {
try {
const sensor = await getSensorDataById(req.params.id);