From 96cb6e857bde16ade4b49fdcc3de73a63e2c5676 Mon Sep 17 00:00:00 2001 From: varun Date: Thu, 8 Jun 2023 04:42:49 -0400 Subject: [PATCH] added tank hardware id in iot data --- src/controllers/tanksController.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 54e65a2d..bc814f40 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -956,19 +956,19 @@ exports.calculateCapacity = async (req, reply) => { exports.IotDevice = async (req, reply) => { try { - const { hardwareId, tankHeight, maxLevel, minLevel, mode } = req.body; + const { hardwareId, tankHeight, maxLevel, minLevel, mode,tankhardwareId } = req.body; // create a new tank document with the current date and time const currentDate = new Date(); const date = currentDate.toISOString(); // save the date as an ISO string const time = currentDate.toLocaleTimeString('en-IN', {hour12:false, timeZone: 'Asia/Kolkata' }); - const tank = new IotData({ hardwareId, tankHeight, maxLevel, minLevel, mode, date, time }); + const tank = new IotData({ hardwareId, tankHeight, maxLevel, minLevel, mode, date, time, tankhardwareId}); // save the document to MongoDB await tank.save(); // get all the tank documents for the current hardwareId sorted in descending order of date and time - const tanks = await IotData.find({ hardwareId }).sort({ date: -1, time: -1 }); + const tanks = await IotData.find({ hardwareId,tankhardwareId }).sort({ date: -1, time: -1 }); // if the number of documents for the current hardwareId is greater than three, remove the oldest documents until there are only three left if (tanks.length > 3) { @@ -979,7 +979,7 @@ exports.IotDevice = async (req, reply) => { } // get the latest three tank documents for the current hardwareId sorted in descending order of date and time - const latestTanks = await IotData.find({ hardwareId }).sort({ date: -1, time: -1 }).limit(3); + const latestTanks = await IotData.find({ hardwareId,tankhardwareId }).sort({ date: -1, time: -1 }).limit(3); // send the latest three documents in descending order of date and time reply.code(200).send({ latestTanks: latestTanks.reverse() });