task push notification

This commit is contained in:
Sibunnayak 2024-09-03 11:08:26 +05:30
parent 76bd4c2c22
commit eb135606e0
2 changed files with 43 additions and 43 deletions

Binary file not shown.

View File

@ -21,16 +21,16 @@ export const updateOverdueTasks = async () => {
task.taskStatus = "Pending"; task.taskStatus = "Pending";
await task.save(); await task.save();
// Fetch the Sales Coordinator who is assigned the task // Fetch the Sales Coordinator who is assigned the task
// const salesCoordinator = await SalesCoOrdinator.findById(task.taskAssignedTo); const salesCoordinator = await SalesCoOrdinator.findById(task.taskAssignedTo);
// if (salesCoordinator) { if (salesCoordinator) {
// const fcmToken = salesCoordinator.fcm_token; const fcmToken = salesCoordinator.fcm_token;
// if (fcmToken) { if (fcmToken) {
// // Send push notification // Send push notification
// const message = `Your task "${task.task}" is Pending.`; const message = `Your task "${task.task}" is Pending.`;
// await sendPushNotification(fcmToken, "Task Status Updated", message); await sendPushNotification(fcmToken, "Task Status Updated", message);
// } }
// } }
} }
console.log('Overdue tasks updated to "Pending".'); console.log('Overdue tasks updated to "Pending".');
@ -107,22 +107,22 @@ export const assignTask = async (req, res) => {
tradename, tradename,
}); });
// Fetch the FCM token of the assigned sales coordinator // Fetch the FCM token of the assigned sales coordinator
// const salesCoordinator = await SalesCoOrdinator.findById(taskAssignedTo); const salesCoordinator = await SalesCoOrdinator.findById(taskAssignedTo);
// if (!salesCoordinator) { if (!salesCoordinator) {
// return res.status(404).json({ return res.status(404).json({
// success: false, success: false,
// message: "Sales Coordinator not found.", message: "Sales Coordinator not found.",
// }); });
// } }
// const fcmToken = salesCoordinator.fcm_token; const fcmToken = salesCoordinator.fcm_token;
// if (fcmToken) { if (fcmToken) {
// // Send push notification // Send push notification
// const message = `You have been assigned a new task: ${task}`; const message = `You have been assigned a new task: ${task}`;
// await sendPushNotification(fcmToken, "New Task Assigned", message); await sendPushNotification(fcmToken, "New Task Assigned", message);
// } }
res.status(201).json({ res.status(201).json({
success: true, success: true,
message: "Task assigned successfully", message: "Task assigned successfully",
@ -253,32 +253,32 @@ export const updateTaskStatus = async (req, res) => {
task.taskStatus = "Completed"; task.taskStatus = "Completed";
await task.save(); await task.save();
// Fetch the Sales Coordinator who completed the task // Fetch the Sales Coordinator who completed the task
// const salesCoordinator = await SalesCoOrdinator.findById(req.user._id); const salesCoordinator = await SalesCoOrdinator.findById(req.user._id);
// if (!salesCoordinator) { if (!salesCoordinator) {
// return res.status(404).json({ return res.status(404).json({
// success: false, success: false,
// message: "Sales Coordinator not found.", message: "Sales Coordinator not found.",
// }); });
// } }
// Fetch the FCM token of the Territory Manager // Fetch the FCM token of the Territory Manager
// const territoryManager = await TerritoryManager.findById(task.taskAssignedBy); const territoryManager = await TerritoryManager.findById(task.taskAssignedBy);
// if (!territoryManager) { if (!territoryManager) {
// return res.status(404).json({ return res.status(404).json({
// success: false, success: false,
// message: "Territory Manager not found.", message: "Territory Manager not found.",
// }); });
// } }
// const fcmToken = territoryManager.fcm_token; const fcmToken = territoryManager.fcm_token;
// if (fcmToken) { if (fcmToken) {
// // Send push notification // Send push notification
// const message = `Task "${task.task}" has been completed by ${salesCoordinator.name}.`; const message = `Task "${task.task}" has been completed by ${salesCoordinator.name}.`;
// await sendPushNotification(fcmToken, "Task Completed", message); await sendPushNotification(fcmToken, "Task Completed", message);
// } }
res.status(200).json({ res.status(200).json({
success: true, success: true,
message: "Task status updated to Completed.", message: "Task status updated to Completed.",