backend validation wip
This commit is contained in:
@ -23,8 +23,8 @@ router.get("/", async (req, res, next) => {
|
||||
|
||||
router.post("/new", async (req, res, next) => {
|
||||
try {
|
||||
const { sensortype, added_by, description, location } = req.body;
|
||||
await addSensor(sensortype, added_by, description, location);
|
||||
const { sensorname, added_by, mac_address , description, location } = req.body;
|
||||
await addSensor(sensorname, added_by, mac_address ,description, location);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
@ -33,8 +33,8 @@ router.post("/new", async (req, res, next) => {
|
||||
|
||||
router.put("/update", async (req, res, next) => {
|
||||
try {
|
||||
const { id, sensortype, added_by, description, location } = req.body;
|
||||
await updateSensor(id, sensortype, added_by, description, location);
|
||||
const { id, sensorname, added_by, mac_address ,description, location } = req.body;
|
||||
await updateSensor(id, sensorname, added_by, mac_address , description, location);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
|
68
Web-Server/routes/SensorData.js
Normal file
68
Web-Server/routes/SensorData.js
Normal file
@ -0,0 +1,68 @@
|
||||
const { sequelize } = require("../../Database/mySql.js");
|
||||
const { sensorDataModel } = require("../../Database/model/sensorDataModel.js");
|
||||
const {
|
||||
getSensorData,
|
||||
addSensorData,
|
||||
updateSensorData,
|
||||
deleteSensorData,
|
||||
getSensorDataById,
|
||||
|
||||
} = require("../functions/APIDatabase.js");
|
||||
|
||||
const express = require("express");
|
||||
const { json } = require("body-parser");
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", async (req, res, next) => {
|
||||
try {
|
||||
const sensor = await getSensorData();
|
||||
res.json(sensor);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/new", async (req, res, next) => {
|
||||
try {
|
||||
//JSON.parse(d) /* d is the parameter of the method 'add()' */
|
||||
|
||||
const { id, id_sensor, id_location, sensordata } = req.body;
|
||||
await addSensorData(id , id_sensor , id_location , sensordata);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
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 );
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.delete("/delete", async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.body;
|
||||
await deleteSensorData(id);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/:id", async (req, res, next) => {
|
||||
try {
|
||||
const sensor = await getSensorDataById(req.params.id);
|
||||
res.json(sensor);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
@ -23,12 +23,14 @@ router.use('/location', require('./Location'));
|
||||
//sensor route
|
||||
router.use('/sensor', require('./Sensor'))
|
||||
|
||||
//sensor data route
|
||||
router.use('/sensor-data', require('./SensorData'));
|
||||
|
||||
|
||||
|
||||
|
||||
router.use('/test' , require('./test'));
|
||||
router.use('/latest-data', require('./latest-data'));
|
||||
router.use('/:month', require('./monthlyData'));
|
||||
|
||||
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
const { sequelize } = require("../../Database/mySql.js");
|
||||
const { IoTModel } = require("../../Database/model/IoTModel.js");
|
||||
const { getallData } = require("../functions/APIDatabase.js");
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
//get month from url
|
||||
console.log(req.params.month);
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
|
||||
// Export the router
|
||||
module.exports = router;
|
Reference in New Issue
Block a user