notifications changes

master^2
Bhaskar 9 months ago
parent 4f51941292
commit 45a0b540a1

@ -1564,30 +1564,32 @@ admin.initializeApp({
// await sendNotification(fcmTokens, 'Motor Started', `Motor ID: ${motorId} started successfully at ${timestamp}. Current Water Level: ${waterLevel} Ltrs`);
// });
eventEmitter.on('motorStart', async (fcmTokens, timestamp, motorId, waterLevel, blockName, tankName, startTime, motorOnType, stopCriteria,stopTime) => {
// const message = `Water supply from '${blockName}' to '${tankName}' started at ${startTime} by '${motorOnType}' mode and will stop after ${stopCriteria}. Current Water Level: ${waterLevel} Ltrs.`;
// await sendNotification(fcmTokens, 'Motor Started', message);
try {
// Retrieve the user information
const users = await User.find({ fcmIds: { $in: fcmTokens } });
console.log("users",users)
const userNames = users.map(user => user.username).join(', ');
console.log("userNames",userNames)
// Prepare the message
// const message = `Tank Name: '${tankName}', Pump started at '${startTime}' by Initiated by user(s): ${userNames} '${motorOnType}' and will stop after '${stopTime}'`;
const message =
`Tank Name: '${tankName}'\n` +
`Pump started at: '${startTime}'\n` +
`Initiated by user(s): ${userNames}\n` +
`Pump started by: '${motorOnType.toUpperCase()}'\n` +
`Will stop at: '${stopTime}'`;
// Send the notification
await sendNotification(fcmTokens, 'Arminta Water Management', message);
} catch (error) {
console.error('Error in motorStart event:', error);
eventEmitter.on(
'motorStart',
async (fcmTokens, timestamp, motorId, waterLevel, blockName, tankName, startTime, motorOnType, stopCriteria, manual_threshold_time) => {
try {
// Retrieve the user information
const users = await User.find({ fcmIds: { $in: fcmTokens } });
console.log("users", users);
const userNames = users.map(user => user.username).join(', ');
console.log("userNames", userNames);
// Prepare the message
const message =
`Tank Name: '${tankName}'\n` +
`Pump started at: '${startTime}'\n` +
`Initiated by user(s): ${userNames}\n` +
`Pump started by: '${motorOnType.toUpperCase()}'\n` +
`Will stop at: '${manual_threshold_time}'`;
// Send the notification
await sendNotification(fcmTokens, 'Arminta Water Management', message);
} catch (error) {
console.error('Error in motorStart event:', error);
}
}
});
);
eventEmitter.on('motorStop', async (fcmTokens, tankName,stopTime, motorOnType) => {
try {
@ -2147,7 +2149,7 @@ console.log(fcmToken)
let motorStopStatus;
const blockName = req.body.from || "Unknown Block"; // Provide a fallback if `from` is missing
const tankName = req.body.to || "Unknown Tank"; // Provide a fallback if `to` is missing
const stopTime = req.body.stopTime || new Date().toISOString();
const stopTime = req.body.stopTime
const motorOnType = req.body.motor_on_type || "app";
if (action === "start") {

Loading…
Cancel
Save