preferences added in notification api

master^2
Bhaskar 8 months ago
parent b91f381ca1
commit 080dba3e86

@ -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);
@ -6929,3 +6935,16 @@ exports.listofactiveandinactivetankstatus = async (req, reply) => {
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" });
}

@ -1354,6 +1354,38 @@ module.exports = function (fastify, opts, next) {
handler: tanksController.sendUserSetNotifications,
});
fastify.route({
method: "POST",
url: "/api/sendNotificationDailyPreference",
schema: {
tags: ["Tank"],
summary: "This is for time based notification preferences",
body: {
type: "object",
properties: {
customerId: {
type: "string",
},
notificationPreference: {
type: "string",
},
// allowNotifications: {
// type: "boolean"
// }
},
},
security: [
{
basicAuth: [],
},
],
},
//preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.notificationTiming,
});
fastify.route({
method: "GET",
url: "/api/listofactiveandinactivetankstatus/:customerId",

Loading…
Cancel
Save