task push notification
This commit is contained in:
parent
76bd4c2c22
commit
eb135606e0
BIN
public/temp/tmp-1-1725339783126
Normal file
BIN
public/temp/tmp-1-1725339783126
Normal file
Binary file not shown.
@ -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);
|
||||
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.",
|
||||
|
Loading…
Reference in New Issue
Block a user