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