master^2
Bhaskar 9 months ago
parent 2aa62e7d6c
commit 989cfcdf52

@ -2909,6 +2909,7 @@ exports.motorAction = async (req, reply) => {
? `${req.body.manual_threshold_time} minutes` ? `${req.body.manual_threshold_time} minutes`
: `${req.body.manual_threshold_litres} litres`; : `${req.body.manual_threshold_litres} litres`;
try { try {
console.log("enter the start")
eventEmitter.emit( eventEmitter.emit(
"motorStart", "motorStart",
customerId, customerId,
@ -3109,29 +3110,29 @@ exports.motorAction = async (req, reply) => {
const notificationKey = `${customerId}_${motorId}_threshold`; const notificationKey = `${customerId}_${motorId}_threshold`;
// Check if the notification has already been sent // Check if the notification has already been sent
if (!notificationTracker.get(notificationKey)) { // if (!notificationTracker.get(notificationKey)) {
console.log("Sending threshold time notification..."); // console.log("Sending threshold time notification...");
eventEmitter.emit( // eventEmitter.emit(
"sendThresholdTimeNotification", // "sendThresholdTimeNotification",
customerId, // customerId,
fcmToken, // fcmToken,
manual_threshold_time, // manual_threshold_time,
motorId, // motorId,
tankName, // tankName,
blockName // blockName
); // );
// Mark notification as sent // // Mark notification as sent
notificationTracker.set(notificationKey, true); // notificationTracker.set(notificationKey, true);
// Optionally, reset the flag after some time (e.g., 24 hours) // // Optionally, reset the flag after some time (e.g., 24 hours)
setTimeout(() => { // setTimeout(() => {
notificationTracker.delete(notificationKey); // notificationTracker.delete(notificationKey);
}, 24 * 60 * 60 * 1000); // Reset after 24 hours // }, 24 * 60 * 60 * 1000); // Reset after 24 hours
} else { // } else {
console.log("Notification already sent, skipping..."); // console.log("Notification already sent, skipping...");
} // }
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
await Tank.updateOne( await Tank.updateOne(

Loading…
Cancel
Save