From 554b17a5899064f5de001dba3f39785a5c503df5 Mon Sep 17 00:00:00 2001 From: Dawid Kubicki Date: Sat, 12 Jan 2019 21:07:32 +0100 Subject: [PATCH] time calculation logic added --- index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.js b/index.js index decdb7d..e2537fa 100644 --- a/index.js +++ b/index.js @@ -94,6 +94,18 @@ app.get("/stop", (req, res) => { res.json({ message: "Przestalem dzialac :<" }); }); +app.get("/status/:id", async (req, res) => { + const data = await statusSchema + .findOne({ + device: mongoose.Types.ObjectId(req.params.id) + }) + .select("status"); + const status = data.status.sort((a, b) => { + return b.time - a.time; + }); + res.json(status); +}); + app.get("/start", (req, res) => { if (interval === null) { interval = setInterval(() => {