Update API routes and sensor data functionality And API.ejs

This commit is contained in:
newtbot
2024-01-30 02:59:14 +08:00
parent 8836a3cfd4
commit 129ca202c0
10 changed files with 849 additions and 176 deletions

View File

@ -19,7 +19,7 @@ router.use('/sensor', [auth, APIlogger], require('./sensor.js'));
router.use('/sensor-data', [auth, APIlogger], require('./sensorData.js'));
//apilog route
router.use('/apilog', [APIlogger], require('./apilog.js'));
router.use('/apilog', [auth, APIlogger], require('./apilog.js'));
//latest sensor data to display on dashboard
router.use('/latest-sensor-data', [APIlogger], require('./latestsensorData.js'));

View File

@ -12,6 +12,7 @@ router.get("/", async (req, res, next) => {
res.json(Res);
});
/*
//get by route name?
router.get("/route/:name", async (req, res, next) => {
});
@ -27,6 +28,8 @@ router.get("/method/:method", async (req, res, next) => {
//by ip
router.get("/ip/:ip", async (req, res, next) => {
});
*/

View File

@ -23,8 +23,9 @@ router.get("/", async (req, res, next) => {
router.post("/new", async (req, res, next) => {
try {
const { id_sensor, id_location, sensordata } = req.body;
let data = await addSensorData(id_sensor, id_location, sensordata);
//locationid
const { sensorid , locationid , measurement } = req.body;
let data = await addSensorData(sensorid , locationid , measurement);
res.json({ message: "SensorData " + data.id + " added", ...data });
} catch (error) {
console.error(error);
@ -34,8 +35,8 @@ router.post("/new", async (req, res, next) => {
router.put("/update", async (req, res, next) => {
try {
const { id, id_sensor, id_location, sensordata } = req.body;
await updateSensorData(id, id_sensor, id_location, sensordata);
const { id , sensorid , locationid , measurement } = req.body;
await updateSensorData(id, sensorid , locationid , measurement);
res.status(200).json({ message: "SensorData " + id + " updated" });
} catch (error) {
console.error(error);
@ -55,7 +56,6 @@ router.delete("/delete", async (req, res, next) => {
});
router.get("/data", async (req, res, next) => {
try {
console.log(req.query);
const data = await getData(req.query);
res.status(200).json(data);