delete endpoint modified

This commit is contained in:
Dawid Kubicki 2019-01-13 18:31:17 +01:00
parent 554b17a589
commit 1c44bca071

View File

@ -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" });
});