made changes in tanks controller

master
varun 2 years ago
parent f25cdae8e5
commit 496adc2445

@ -160,14 +160,13 @@ exports.updateTanklevels = async (req, reply) => {
const tankId = tank._id; const tankId = tank._id;
const tank_name = tank.tankName const tank_name = tank.tankName
let capacity = parseInt(tank.capacity.replace(/,/g, ''), 10); let capacity = parseInt(tank.capacity.replace(/,/g, ''), 10);
// let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
const intervalId = setInterval(async function () { const intervalId = setInterval(async function () {
let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); const motorStatus = tank.motor_status
const newWaterLevel = Math.floor(waterLevel - 200); const newWaterLevel = Math.floor(waterLevel - 200);
if (newWaterLevel <= 0) { if (newWaterLevel <= 0,motorStatus === "0") {
clearInterval(intervals[tankId]); clearInterval(intervals[tankId]);
console.log(`Stopped updating tank with ID ${tankId}`); console.log(`Stopped updating tank with ID ${tankId}`);
return; return;
@ -184,7 +183,7 @@ exports.updateTanklevels = async (req, reply) => {
// waterLevel = newWaterLevel; waterLevel = newWaterLevel;
}, 2000); }, 2000);
intervals[tankId] = intervalId; intervals[tankId] = intervalId;

Loading…
Cancel
Save