master^2
Bhaskar 8 months ago
parent 167d04aabb
commit dea38e44e8

@ -1766,7 +1766,7 @@ const sendNotification = async (fcmIds, title, body) => {
notification: { title, body },
token,
data: {
exampleKey: 'exampleValue',
'target': '/tank_levels',
},
});
console.log(`Notification sent successfully to token: ${token}`, response);
@ -2150,16 +2150,17 @@ const checkWaterLevelsAndNotify = async (customerId, tankName, tankLocation, fcm
} else if (waterLevelPercentage <= thresholds.low) {
eventEmitter.emit('sendLowWaterNotification', fcmTokens, tank);
await Tank.updateOne({ customerId, tankName: tank.tankName }, { $set: { notificationSentLow: true } });
} else if (waterLevelPercentage >= thresholds.criticallyHigh) {
eventEmitter.emit('sendCriticalHighWaterNotification', fcmTokens, tank);
await Tank.updateOne({ customerId, tankName: tank.tankName }, { $set: { notificationSentCriticalHigh: true } });
} else if (waterLevelPercentage >= thresholds.veryHigh) {
eventEmitter.emit('sendVeryHighWaterNotification', fcmTokens, tank);
await Tank.updateOne({ customerId, tankName: tank.tankName }, { $set: { notificationSentVeryHigh: true } });
} else if (waterLevelPercentage >= thresholds.high) {
eventEmitter.emit('sendHighWaterNotification', fcmTokens, tank);
await Tank.updateOne({ customerId, tankName: tank.tankName }, { $set: { notificationSentHigh: true } });
}
// else if (waterLevelPercentage >= thresholds.criticallyHigh) {
// eventEmitter.emit('sendCriticalHighWaterNotification', fcmTokens, tank);
// await Tank.updateOne({ customerId, tankName: tank.tankName }, { $set: { notificationSentCriticalHigh: true } });
// } else if (waterLevelPercentage >= thresholds.veryHigh) {
// eventEmitter.emit('sendVeryHighWaterNotification', fcmTokens, tank);
// await Tank.updateOne({ customerId, tankName: tank.tankName }, { $set: { notificationSentVeryHigh: true } });
// } else if (waterLevelPercentage >= thresholds.high) {
// eventEmitter.emit('sendHighWaterNotification', fcmTokens, tank);
// await Tank.updateOne({ customerId, tankName: tank.tankName }, { $set: { notificationSentHigh: true } });
// }
} catch (error) {
console.error(`Error checking water levels for tank ${tankName}:`, error);
}

Loading…
Cancel
Save