blah
This commit is contained in:
@ -7,7 +7,7 @@ const {
|
||||
deleteSensorData,
|
||||
getSensorDataById,
|
||||
|
||||
} = require("../functions/APIDatabase.js");
|
||||
} = require("../functions/apiDatabase.js");
|
||||
|
||||
const express = require("express");
|
||||
const { json } = require("body-parser");
|
||||
@ -16,7 +16,7 @@ const router = express.Router();
|
||||
router.get("/", async (req, res, next) => {
|
||||
try {
|
||||
const sensor = await getSensorData();
|
||||
res.json(sensor);
|
||||
res.status(200).json(sensor);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
@ -25,10 +25,9 @@ router.get("/", async (req, res, next) => {
|
||||
|
||||
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);
|
||||
res.sendStatus(200).json({message: "SensorData " + id + " added" });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
@ -39,6 +38,7 @@ 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 );
|
||||
res.status(200).json({ message: "SensorData " + id + " updated" });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
@ -49,6 +49,7 @@ router.delete("/delete", async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.body;
|
||||
await deleteSensorData(id);
|
||||
res.status(200).json({ message: "SensorData " + id + " deleted" });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
@ -58,7 +59,7 @@ router.delete("/delete", async (req, res, next) => {
|
||||
router.get("/:id", async (req, res, next) => {
|
||||
try {
|
||||
const sensor = await getSensorDataById(req.params.id);
|
||||
res.json(sensor);
|
||||
res.status(200).json(sensor);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
|
Reference in New Issue
Block a user