made changes in tanks controller

master
varun 2 years ago
parent 496adc2445
commit b56117037a

@ -160,13 +160,15 @@ 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);
console.log(waterLevel)
const motorStatus = tank.motor_status const motorStatus = tank.motor_status
const newWaterLevel = Math.floor(waterLevel - 200); const newWaterLevel = Math.floor(waterLevel - 200);
if (newWaterLevel <= 0,motorStatus === "0") { if (newWaterLevel <= 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;
@ -183,7 +185,7 @@ exports.updateTanklevels = async (req, reply) => {
waterLevel = newWaterLevel; //waterLevel = newWaterLevel;
}, 2000); }, 2000);
intervals[tankId] = intervalId; intervals[tankId] = intervalId;

Loading…
Cancel
Save