diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index a7a7252e..df3ac654 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1499,9 +1499,14 @@ exports.motorAction = async (req, reply) => { } ); clearInterval(intervalId); - + + // Send notification after motor stops due to time threshold + if (fcmToken) { + await sendNotification(fcmToken, 'Motor Stopped After Time Threshold', `Motor ${motorId} has been stopped after reaching the set time threshold.`); + } + await delay(300000); - + const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id }); if (motorData) { const receiverTank = await Tank.findOne({ customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() }); @@ -1513,9 +1518,9 @@ exports.motorAction = async (req, reply) => { { customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() }, { $set: { total_water_added_from_midnight: totalwaterpumped } } ); - + const stopTime = formatDate(new Date()); - + await MotorData.updateOne( { customerId, motor_id: motorId, start_instance_id: start_instance_id }, { @@ -1526,7 +1531,6 @@ exports.motorAction = async (req, reply) => { } } ); - // Send low water level notification if (receiverFinalWaterLevel / parseInt(receiverTank.capacity, 10) * 100 <= 20) { if (fcmToken) { @@ -1534,7 +1538,7 @@ exports.motorAction = async (req, reply) => { } } } - } + } }, 60000); } else if (req.body.threshold_type === "litres") { console.log("entered litres")