From 1c44bca071bf319a22aafa4f9154b23d7fdb06f4 Mon Sep 17 00:00:00 2001 From: Dawid Kubicki Date: Sun, 13 Jan 2019 18:31:17 +0100 Subject: [PATCH] delete endpoint modified --- index.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index e2537fa..6cbfd41 100644 --- a/index.js +++ b/index.js @@ -36,14 +36,6 @@ const save_data = async time => { } } catch (error) { console.log("ERROR z CATCHA => " + error); - // const item = new dbSchema({ - // ip, - // status: "Urządzenie przestało działać - prawdopodobnie brak zasilania" - // }); - // item - // .save() - // .then() - // .catch(); } }; @@ -77,7 +69,7 @@ const getScript = url => { }); }) .on("error", err => { - reject(err); + resolve('{"Sensors": [{ "Switch": 2 }]}'); }); }); }; @@ -133,10 +125,10 @@ app.post("/device", async (req, res) => { res.json({ Sukces: "Dodaje OK" }); }); -app.delete("/device/:id", async (req, res) => { +app.delete("/device/:ip", async (req, res) => { console.log(req.body); - const newDevice = await deviceSchema.findByIdAndRemove(req.params.id); - await statusSchema.findOneAndRemove({ device: req.params.id }); + const newDevice = await deviceSchema.findOneAndRemove({ ip: req.params.ip }); + await statusSchema.findOneAndRemove({ device: newDevice }); res.json({ Sukces: "Usuwa OK" }); }); -- 2.20.1