diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 0d7bdcba..3833d83c 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2385,37 +2385,37 @@ const sendNotification = async (customerId, fcmIds, title, body) => { return; } - // Handle notification preference - if (notificationPreference === "never") { - console.log(`Notifications disabled for customer ID: ${customerId}`); - return; - } + // // Handle notification preference + // if (notificationPreference === "never") { + // console.log(`Notifications disabled for customer ID: ${customerId}`); + // return; + // } const now = new Date(); const lastSent = new Date(lastNotificationSent || 0); // If preference is not "always", check the timing - if (notificationPreference !== "always") { - let minInterval = 0; - - switch (notificationPreference) { - case "6_hours": - minInterval = 6 * 60 * 60 * 1000; // 6 hours - break; - case "8_hours": - minInterval = 8 * 60 * 60 * 1000; // 8 hours - break; - case "1_month": - minInterval = 30 * 24 * 60 * 60 * 1000; // 1 month - break; - } - - // Skip sending if the time restriction hasn't passed - if (now - lastSent < minInterval) { - console.log(`Skipping notification for customer ID: ${customerId} due to time restriction.`); - return; - } - } + // if (notificationPreference !== "always") { + // let minInterval = 0; + + // switch (notificationPreference) { + // case "6_hours": + // minInterval = 6 * 60 * 60 * 1000; // 6 hours + // break; + // case "8_hours": + // minInterval = 8 * 60 * 60 * 1000; // 8 hours + // break; + // case "1_month": + // minInterval = 30 * 24 * 60 * 60 * 1000; // 1 month + // break; + // } + + // // Skip sending if the time restriction hasn't passed + // if (now - lastSent < minInterval) { + // console.log(`Skipping notification for customer ID: ${customerId} due to time restriction.`); + // return; + // } + // } // Send notifications const notificationPromises = validTokens.map(async (token) => { @@ -3034,8 +3034,9 @@ exports.motorAction = async (req, reply) => { // await checkWaterLevelsAndNotify(customerId, tankName, receiverTank.tankLocation, fcmToken); if (!notificationSentStatus.motorStart) { + console.log("Emitting motorStart event for customer:", customerId); eventEmitter.emit( - 'motorStart', + "motorStart", customerId, fcmToken, // Ensure this is an array of tokens tankName, @@ -3049,6 +3050,7 @@ exports.motorAction = async (req, reply) => { notificationSentStatus.motorStart = true; // Prevent duplicate notifications } + // Start checking water level every 30 minutes if (!waterLevelCheckInterval) { waterLevelCheckInterval = setInterval(async () => {