From d18ec3f03b1184d6e8884c1ef94115b52785e6f3 Mon Sep 17 00:00:00 2001 From: varun Date: Mon, 27 Feb 2023 03:52:42 -0500 Subject: [PATCH] made changes in tanker --- 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 5de22a34..d2c99a2a 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -140,12 +140,12 @@ exports.getTank = async (req, reply) => { // throw boom.boomify(err); // } //}; - +let intervalTimer; exports.updateTanklevels = async (req, reply) => { try { const customerId = req.params.customerId; const tank = await Tank.find({customerId}); - + clearInterval(intervalTimer); for (var i=0; i < tank.length; i++) { const tankname = tank[i].tankName const capacity = tank[i].capacity @@ -154,7 +154,7 @@ exports.updateTanklevels = async (req, reply) => { //console.log(Number) - setInterval(async function () { + intervalTimer=setInterval(async function () { // const randomNumber = Math.floor(Math.random() * capacity) //const randomNumber = Math.floor(Math.random() * (5500 - 1000) + 1000); @@ -162,7 +162,7 @@ exports.updateTanklevels = async (req, reply) => { //console.log(tankname) const randomNumber = Math.floor(Number/1.5) console.log(randomNumber) - await Tank.findOneAndUpdate({ customerId: customerId, tankName: tankname },{ $set: { waterlevel: randomNumber } }); + await Tank.findOneAndUpdate({ customerId: customerId, tankName: tankname },{ $set: { waterlevel: randomNumber } }, { upsert: true, new: true }); Number = randomNumber //return Number