From f835314efa113eb119a2ad40c4d84b3cdfde48c8 Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 3 May 2023 05:48:14 -0400 Subject: [PATCH 1/8] made changes in tanks controller --- src/controllers/tanksController.js | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 5f74480d..55f234db 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -160,10 +160,11 @@ exports.updateTanklevels = async (req, reply) => { const tankId = tank._id; const tank_name = tank.tankName 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 newWaterLevel = Math.floor(waterLevel - 200); + let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); + const newWaterLevel = Math.floor(waterLevel - 200); if (newWaterLevel <= 0) { clearInterval(intervals[tankId]); @@ -201,33 +202,22 @@ exports.getTanklevels = async (req, reply) => { try { const customerId = req.params.customerId; + const updated_data = await Tank.find({ customerId: customerId }); + + reply.send({ status_code: 200, data: updated_data}); - let sumSumpDrinkingWater = 0; - let sumOverheadDrinkingWater = 0; - updated_data.forEach((tank) => { - if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') { - sumSumpDrinkingWater += parseInt(tank.waterlevel); - } else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Drinking Water') { - sumOverheadDrinkingWater += parseInt(tank.waterlevel); - } - }); - - reply.send({ - status_code: 200, - data: updated_data, - totalDrinkingWaterInSump: sumSumpDrinkingWater, - totalDrinkingWaterInOverhead: sumOverheadDrinkingWater - }); + return { message: 'success' }; +} - return { message: 'success' }; - } catch (err) { + catch (err) { throw boom.boomify(err); } }; + exports.motorAction = async (req, reply) => { try { //let start_time,stop_time From b76437b5d76f6321cc96412c2804c5b79b51e31c Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 3 May 2023 05:52:39 -0400 Subject: [PATCH 2/8] made changes in tanks controller --- src/controllers/tanksController.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index e9480088..3951be03 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -160,10 +160,11 @@ exports.updateTanklevels = async (req, reply) => { const tankId = tank._id; const tank_name = tank.tankName 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 () { - + let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); + const newWaterLevel = Math.floor(waterLevel - 200); if (newWaterLevel <= 0) { From f25cdae8e58de9149a33ef613f9c5614a4404701 Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 3 May 2023 05:54:52 -0400 Subject: [PATCH 3/8] made changes in tanks controller --- src/controllers/tanksController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 3951be03..1f9c42eb 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -184,7 +184,7 @@ exports.updateTanklevels = async (req, reply) => { - waterLevel = newWaterLevel; + // waterLevel = newWaterLevel; }, 2000); intervals[tankId] = intervalId; From 496adc2445042b8d22ff527e43164fbf92d4dab5 Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 3 May 2023 06:08:31 -0400 Subject: [PATCH 4/8] made changes in tanks controller --- src/controllers/tanksController.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 1f9c42eb..5b538940 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -160,14 +160,13 @@ exports.updateTanklevels = async (req, reply) => { const tankId = tank._id; const tank_name = tank.tankName 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 () { - let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); - + const motorStatus = tank.motor_status const newWaterLevel = Math.floor(waterLevel - 200); - if (newWaterLevel <= 0) { + if (newWaterLevel <= 0,motorStatus === "0") { clearInterval(intervals[tankId]); console.log(`Stopped updating tank with ID ${tankId}`); return; @@ -184,7 +183,7 @@ exports.updateTanklevels = async (req, reply) => { - // waterLevel = newWaterLevel; + waterLevel = newWaterLevel; }, 2000); intervals[tankId] = intervalId; From b56117037a822e0d6fe03f2c05736aa4df6d342e Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 3 May 2023 06:16:32 -0400 Subject: [PATCH 5/8] made changes in tanks controller --- src/controllers/tanksController.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 5b538940..4859a61a 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -160,13 +160,15 @@ exports.updateTanklevels = async (req, reply) => { const tankId = tank._id; const tank_name = tank.tankName 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 () { + let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); + console.log(waterLevel) const motorStatus = tank.motor_status const newWaterLevel = Math.floor(waterLevel - 200); - if (newWaterLevel <= 0,motorStatus === "0") { + if (newWaterLevel <= 0) { clearInterval(intervals[tankId]); console.log(`Stopped updating tank with ID ${tankId}`); return; @@ -183,7 +185,7 @@ exports.updateTanklevels = async (req, reply) => { - waterLevel = newWaterLevel; + //waterLevel = newWaterLevel; }, 2000); intervals[tankId] = intervalId; From d03c8cdd8970b4bb3234c4eeb7d434ff7f2cf8ed Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 3 May 2023 06:45:01 -0400 Subject: [PATCH 6/8] made changes in tanks controller --- src/controllers/tanksController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 4859a61a..8f397f23 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -163,7 +163,7 @@ exports.updateTanklevels = async (req, reply) => { // let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); const intervalId = setInterval(async function () { - let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); + const waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); console.log(waterLevel) const motorStatus = tank.motor_status const newWaterLevel = Math.floor(waterLevel - 200); From 9a5e5291c46dd779af9aac666ae294c41758951c Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 3 May 2023 07:05:00 -0400 Subject: [PATCH 7/8] made changes in tanks controller --- src/controllers/tanksController.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 8f397f23..c8a156d8 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -160,7 +160,7 @@ exports.updateTanklevels = async (req, reply) => { const tankId = tank._id; const tank_name = tank.tankName 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 waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); @@ -168,7 +168,7 @@ exports.updateTanklevels = async (req, reply) => { const motorStatus = tank.motor_status const newWaterLevel = Math.floor(waterLevel - 200); - if (newWaterLevel <= 0) { + if (newWaterLevel <= 0,motorStatus === "1") { clearInterval(intervals[tankId]); console.log(`Stopped updating tank with ID ${tankId}`); return; @@ -185,7 +185,7 @@ exports.updateTanklevels = async (req, reply) => { - //waterLevel = newWaterLevel; + waterLevel = newWaterLevel; }, 2000); intervals[tankId] = intervalId; From 944647b2e0ca7aeb0aadc0717e986cf9fe806c48 Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 3 May 2023 07:10:29 -0400 Subject: [PATCH 8/8] made changes in tanks controller --- src/controllers/tanksController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index c8a156d8..659d7dd0 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -163,10 +163,10 @@ exports.updateTanklevels = async (req, reply) => { let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); const intervalId = setInterval(async function () { - const waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); console.log(waterLevel) const motorStatus = tank.motor_status const newWaterLevel = Math.floor(waterLevel - 200); + console.log("motorstatus:"+motorStatus) if (newWaterLevel <= 0,motorStatus === "1") { clearInterval(intervals[tankId]);