diff --git a/public/temp/tmp-1-1724818772218 b/public/temp/tmp-1-1724818772218 new file mode 100644 index 0000000..8b6df1b Binary files /dev/null and b/public/temp/tmp-1-1724818772218 differ diff --git a/public/temp/tmp-2-1724818809400 b/public/temp/tmp-2-1724818809400 new file mode 100644 index 0000000..1a8fade Binary files /dev/null and b/public/temp/tmp-2-1724818809400 differ diff --git a/public/temp/tmp-3-1724819002571 b/public/temp/tmp-3-1724819002571 new file mode 100644 index 0000000..1a8fade Binary files /dev/null and b/public/temp/tmp-3-1724819002571 differ diff --git a/public/temp/tmp-4-1724819035891 b/public/temp/tmp-4-1724819035891 new file mode 100644 index 0000000..8b6df1b Binary files /dev/null and b/public/temp/tmp-4-1724819035891 differ diff --git a/resources/Task/TaskController.js b/resources/Task/TaskController.js index 8658581..cf2aba7 100644 --- a/resources/Task/TaskController.js +++ b/resources/Task/TaskController.js @@ -1,6 +1,7 @@ import Task from "./TaskModel.js"; import crypto from "crypto"; -import cron from 'node-cron'; +import cron from "node-cron"; + // Function to update task statuses const updateOverdueTasks = async () => { try { @@ -9,28 +10,33 @@ const updateOverdueTasks = async () => { // Find tasks where dueDate is before the current date and status is "New" const overdueTasks = await Task.find({ - taskDueDate: { $lt: currentDateOnly.toISOString().split('T')[0] }, - taskStatus: 'New', + taskDueDate: { $lt: currentDateOnly }, + taskStatus: "New", }); // Update tasks to "Pending" for (const task of overdueTasks) { - task.taskStatus = 'Pending'; + task.taskStatus = "Pending"; await task.save(); } console.log('Overdue tasks updated to "Pending".'); } catch (error) { - console.error('Error updating overdue tasks:', error); + console.error("Error updating overdue tasks:", error); } }; // Schedule the cron job to run daily at midnight cron.schedule('0 0 * * *', updateOverdueTasks); + // Schedule the cron job to run daily at 10:36 AM for testing +// cron.schedule("36 10 * * *", updateOverdueTasks); const parseDate = (dateStr) => { - const [day, month, year] = dateStr.split('/').map(Number); - return new Date(year, month - 1, day); + const [day, month, year] = dateStr.split("/").map(Number); + // Create a date object in local timezone + const localDate = new Date(year, month - 1, day); + // Convert to a date with time set to the start of the day in UTC + return new Date(Date.UTC(year, month - 1, day)); }; export const assignTask = async (req, res) => { @@ -51,10 +57,10 @@ export const assignTask = async (req, res) => { const currentDate = new Date(); // Set the time of the currentDate to the start of the day for comparison - currentDate.setHours(0, 0, 0, 0); + const currentDateOnly = new Date(Date.UTC(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate())); // Check if the due date is in the past - if (dueDate < currentDate) { + if (dueDate < currentDateOnly) { return res.status(400).json({ success: false, message: "Due date cannot be earlier than the current date.", @@ -128,7 +134,14 @@ export const getTasksbytask = async (req, res) => { const { task } = req.params; // Validate the provided status - if (!["Visit RD/PD", "Update Sales Data", "Update Inventory Data", "Collect KYC"].includes(task)) { + if ( + ![ + "Visit RD/PD", + "Update Sales Data", + "Update Inventory Data", + "Collect KYC", + ].includes(task) + ) { return res.status(400).json({ success: false, message: "Invalid task type provided.", @@ -154,7 +167,10 @@ export const updateTaskStatus = async (req, res) => { try { const { taskId } = req.params; - const task = await Task.findOne({ _id: taskId, taskAssignedTo: req.user._id }); + const task = await Task.findOne({ + _id: taskId, + taskAssignedTo: req.user._id, + }); if (!task) { return res.status(404).json({