diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index b0ac104c..5a98008a 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2502,7 +2502,22 @@ exports.motorAction = async (req, reply) => { // console.log(motorIntervals[motorId],"deleted automatically") // Emit low water level notification // clearInterval(motorIntervals[motorId]); // Clear interval // delete motorIntervals[motorId]; + await checkWaterLevelsAndNotify(customerId, tankName, supplierTank.tankLocation, fcmToken); + if (currentWaterPercentage >= highWaterThreshold && !notificationSentStatus.highWater) { + eventEmitter.emit('sendHighWaterNotification', fcmToken, `Water level has reached high levels.`); + notificationSentStatus.highWater = true; // Set flag to true to prevent duplicate notifications + } + + if (currentWaterPercentage >= veryHighWaterThreshold && !notificationSentStatus.veryHighWater) { + eventEmitter.emit('sendVeryHighWaterNotification', fcmToken, `Water level has reached very high levels.`); + notificationSentStatus.veryHighWater = true; // Set flag to true to prevent duplicate notifications + } + + if (currentWaterPercentage >= criticalHighWaterThreshold && !notificationSentStatus.criticallyHighWater) { + eventEmitter.emit('sendCriticalHighWaterNotification', fcmToken, `Water level has reached critically high levels.`); + notificationSentStatus.criticallyHighWater = true; // Set flag to true to prevent duplicate notifications + } clearInterval(motorIntervals[motorId]); // Stop the motor if condition met delete motorIntervals[motorId]; // Remove from interval object @@ -2535,11 +2550,11 @@ exports.motorAction = async (req, reply) => { } // Check for high water level and send notification - if (currentWaterPercentage >= highWaterThreshold) { - // eventEmitter.emit('sendHighWaterNotification', fcmToken, receiverTank); - await checkWaterLevelsAndNotify(customerId, tankName, supplierTank.tankLocation, fcmToken); + // if (currentWaterPercentage >= highWaterThreshold) { + // // eventEmitter.emit('sendHighWaterNotification', fcmToken, receiverTank); + // await checkWaterLevelsAndNotify(customerId, tankName, supplierTank.tankLocation, fcmToken); - } + // } }, 30000); // Check every minute }