|
|
|
@ -11,6 +11,8 @@ const cron = require('node-cron');
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
|
|
const EventEmitter = require('events');
|
|
|
|
|
EventEmitter.defaultMaxListeners = 50; // Increase listener limit
|
|
|
|
|
|
|
|
|
|
const eventEmitter = new EventEmitter();
|
|
|
|
|
async function deleteOldRecords() {
|
|
|
|
|
const SEVEN_DAYS_IN_MILLISECONDS = 7 * 24 * 60 * 60 * 1000;
|
|
|
|
@ -2424,7 +2426,11 @@ const sendNotification = async (customerId, fcmIds, title, body) => {
|
|
|
|
|
data: { target: "/tank_levels" },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log(`Notification sent successfully to token: ${token}`, response);
|
|
|
|
|
console.log(`Notification sent successfully to token: ${token}`);
|
|
|
|
|
console.log("FCM Response:", response); // Log the full response
|
|
|
|
|
console.log(`Title: ${title}, Body: ${body}`); // Log title and body before sending
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`Failed to send notification to token: ${token}`, error);
|
|
|
|
|
|
|
|
|
@ -6928,4 +6934,17 @@ exports.listofactiveandinactivetankstatus = async (req, reply) => {
|
|
|
|
|
console.error("Error fetching tank list:", error);
|
|
|
|
|
return reply.code(500).send({ message: "Internal Server Error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.notificationTiming = async (req, reply) => {
|
|
|
|
|
const { customerId, notificationPreference } = req.body;
|
|
|
|
|
|
|
|
|
|
if (!["never", "always", "6_hours", "8_hours", "1_month"].includes(notificationPreference)) {
|
|
|
|
|
return reply.status(400).send({ message: "Invalid preference" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await User.updateOne({ customerId }, { notificationPreference });
|
|
|
|
|
|
|
|
|
|
return reply.send({ message: "Preference updated successfully" });
|
|
|
|
|
}
|