diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 27d6f5d7..c49cacea 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2952,6 +2952,22 @@ exports.motorAction = async (req, reply) => { const totalWaterPumped = await calculateTotalPumpedWater(customerId, motorId, start_instance_id); + const lowWaterThreshold = 5; // Adjust as needed + const thresholdTime = new Date(manual_threshold_time); // Convert threshold time + + if (new Date() >= thresholdTime || currentWaterPercentage <= lowWaterThreshold) { + console.log("Motor stopping because it entered this condition"); + + eventEmitter.emit( + "sendThresholdTimeNotification", + customerId, + fcmToken, + manual_threshold_time, + motorId + ); + } + + console.log("Motor stopped"); eventEmitter.emit("motorStop", customerId, fcmToken, tankName, blockName, stopTime, "Mobile APP", totalWaterPumped, typeOfWater, motorId, loggedInUser.phone,);