diff --git a/public/temp/tmp-1-1725339783126 b/public/temp/tmp-1-1725339783126 new file mode 100644 index 0000000..3ca99fd Binary files /dev/null and b/public/temp/tmp-1-1725339783126 differ diff --git a/resources/Task/TaskController.js b/resources/Task/TaskController.js index a97deaa..1347f09 100644 --- a/resources/Task/TaskController.js +++ b/resources/Task/TaskController.js @@ -21,16 +21,16 @@ export const updateOverdueTasks = async () => { task.taskStatus = "Pending"; await task.save(); // 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) { - // const fcmToken = salesCoordinator.fcm_token; - // if (fcmToken) { - // // Send push notification - // const message = `Your task "${task.task}" is Pending.`; - // await sendPushNotification(fcmToken, "Task Status Updated", message); - // } - // } + if (salesCoordinator) { + const fcmToken = salesCoordinator.fcm_token; + if (fcmToken) { + // Send push notification + const message = `Your task "${task.task}" is Pending.`; + await sendPushNotification(fcmToken, "Task Status Updated", message); + } + } } console.log('Overdue tasks updated to "Pending".'); @@ -107,22 +107,22 @@ export const assignTask = async (req, res) => { tradename, }); // Fetch the FCM token of the assigned sales coordinator - // const salesCoordinator = await SalesCoOrdinator.findById(taskAssignedTo); + const salesCoordinator = await SalesCoOrdinator.findById(taskAssignedTo); - // if (!salesCoordinator) { - // return res.status(404).json({ - // success: false, - // message: "Sales Coordinator not found.", - // }); - // } + if (!salesCoordinator) { + return res.status(404).json({ + success: false, + message: "Sales Coordinator not found.", + }); + } - // const fcmToken = salesCoordinator.fcm_token; + const fcmToken = salesCoordinator.fcm_token; - // if (fcmToken) { - // // Send push notification - // const message = `You have been assigned a new task: ${task}`; - // await sendPushNotification(fcmToken, "New Task Assigned", message); - // } + if (fcmToken) { + // Send push notification + const message = `You have been assigned a new task: ${task}`; + await sendPushNotification(fcmToken, "New Task Assigned", message); + } res.status(201).json({ success: true, message: "Task assigned successfully", @@ -253,32 +253,32 @@ export const updateTaskStatus = async (req, res) => { task.taskStatus = "Completed"; await task.save(); // 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) { - // return res.status(404).json({ - // success: false, - // message: "Sales Coordinator not found.", - // }); - // } + if (!salesCoordinator) { + return res.status(404).json({ + success: false, + message: "Sales Coordinator not found.", + }); + } - // Fetch the FCM token of the Territory Manager - // const territoryManager = await TerritoryManager.findById(task.taskAssignedBy); + // Fetch the FCM token of the Territory Manager + const territoryManager = await TerritoryManager.findById(task.taskAssignedBy); - // if (!territoryManager) { - // return res.status(404).json({ - // success: false, - // message: "Territory Manager not found.", - // }); - // } + if (!territoryManager) { + return res.status(404).json({ + success: false, + message: "Territory Manager not found.", + }); + } - // const fcmToken = territoryManager.fcm_token; + const fcmToken = territoryManager.fcm_token; - // if (fcmToken) { - // // Send push notification - // const message = `Task "${task.task}" has been completed by ${salesCoordinator.name}.`; - // await sendPushNotification(fcmToken, "Task Completed", message); - // } + if (fcmToken) { + // Send push notification + const message = `Task "${task.task}" has been completed by ${salesCoordinator.name}.`; + await sendPushNotification(fcmToken, "Task Completed", message); + } res.status(200).json({ success: true, message: "Task status updated to Completed.",