From da1aeec6671dc97ca1aa6e8d12177103fdf607a8 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 5 Mar 2025 15:01:48 +0530 Subject: [PATCH] changes --- src/controllers/tanksController.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index dfd93de7..0a827b97 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1441,7 +1441,7 @@ eventEmitter.on( `🕒 Pump started at: ${startTime} \n` + `Will stop after: '${manual_threshold_time}' mins`; - await sendNotification(hw_Id, customerId, fcmTokens, "Arminta MOTOR STARTED", message); + await sendNotification(hw_Id, customerId, fcmTokens, "ARMINTA : MOTOR STARTED", message); } catch (error) { console.error("Error in motorStart event:", error); } @@ -1502,7 +1502,7 @@ eventEmitter.on( `🕒 Pump stopped at: ${stopTime}\n` + `💧 Total water pumped: ${totalWaterPumped} liters\n`; - await sendNotification(hw_Id, customerId, fcmTokens, "Arminta MOTOR STOPPED", message); + await sendNotification(hw_Id, customerId, fcmTokens, "ARMINTA : MOTOR STOPPED", message); } catch (error) { console.error("Error in motorStop event:", error); } @@ -1571,18 +1571,13 @@ eventEmitter.on('sendCriticalHighWaterNotification', async (fcmTokens, tankInfo, // await sendNotification(fcmTokens, 'High Water Level', `Motor ID: ${motorId}, water level reached above 90% at ${timestamp}. Current Water Level: ${waterLevel} Ltrs`); // }); -// eventEmitter.on('sendThresholdTimeNotification', async (fcmTokens, message) => { -// try { -// await sendNotification(fcmTokens, 'Threshold Time Reached', message, 'Motor Alert'); -// console.log("Threshold time notification sent successfully."); -// } catch (error) { -// console.error("Error sending threshold time notification:", error); -// } -// }); -eventEmitter.on('sendThresholdTimeNotification', async (customerId, fcmTokens, thresholdTime, hw_Id) => { +eventEmitter.on('sendThresholdTimeNotification', async (customerId, fcmTokens, thresholdTime, hw_Id, tankName, blockName) => { try { - const message = `Motor Stopped as it completed ${thresholdTime} minutes.`; + const message = + `🛢️ Tank Name: '${tankName}'\n` + + `🏢 Block Name: '${blockName}'\n` + + `Motor Stopped as it completed ${thresholdTime} minutes.`; await sendNotification(hw_Id, customerId, fcmTokens, 'Motor Alert', message); console.log("Threshold time notification sent successfully."); } catch (error) { @@ -3087,17 +3082,15 @@ exports.motorAction = async (req, reply) => { console.log(thresholdTime,"thresholdTime") console.log("motor stopping because it entered this condition") // Emit the threshold time notification - // eventEmitter.emit( - // "sendThresholdTimeNotification", - // fcmToken, - // `Motor has reached its time threshold of ${req.body.manual_threshold_time} minutes and will stop.` - // ); + eventEmitter.emit( "sendThresholdTimeNotification", customerId, fcmToken, manual_threshold_time, - motorId + motorId, + tankName, + blockName ); const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); await Tank.updateOne(