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() }); diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index c8645c4d..95ad43f0 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -343,7 +343,7 @@ module.exports = function (fastify, opts, next) { tankHeight: { type: "string"}, maxLevel: { type: "string" }, minLevel: { type: "string" }, - + tankhardwareId:{ type: "string" }, mode: { type: "string" }, }, },