product manual completed
This commit is contained in:
parent
4775d20253
commit
5d91747fa1
BIN
public/temp/tmp-1-1724818772218
Normal file
BIN
public/temp/tmp-1-1724818772218
Normal file
Binary file not shown.
BIN
public/temp/tmp-2-1724818809400
Normal file
BIN
public/temp/tmp-2-1724818809400
Normal file
Binary file not shown.
BIN
public/temp/tmp-3-1724819002571
Normal file
BIN
public/temp/tmp-3-1724819002571
Normal file
Binary file not shown.
BIN
public/temp/tmp-4-1724819035891
Normal file
BIN
public/temp/tmp-4-1724819035891
Normal file
Binary file not shown.
@ -1,6 +1,7 @@
|
|||||||
import Task from "./TaskModel.js";
|
import Task from "./TaskModel.js";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import cron from 'node-cron';
|
import cron from "node-cron";
|
||||||
|
|
||||||
// Function to update task statuses
|
// Function to update task statuses
|
||||||
const updateOverdueTasks = async () => {
|
const updateOverdueTasks = async () => {
|
||||||
try {
|
try {
|
||||||
@ -9,28 +10,33 @@ const updateOverdueTasks = async () => {
|
|||||||
|
|
||||||
// Find tasks where dueDate is before the current date and status is "New"
|
// Find tasks where dueDate is before the current date and status is "New"
|
||||||
const overdueTasks = await Task.find({
|
const overdueTasks = await Task.find({
|
||||||
taskDueDate: { $lt: currentDateOnly.toISOString().split('T')[0] },
|
taskDueDate: { $lt: currentDateOnly },
|
||||||
taskStatus: 'New',
|
taskStatus: "New",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update tasks to "Pending"
|
// Update tasks to "Pending"
|
||||||
for (const task of overdueTasks) {
|
for (const task of overdueTasks) {
|
||||||
task.taskStatus = 'Pending';
|
task.taskStatus = "Pending";
|
||||||
await task.save();
|
await task.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Overdue tasks updated to "Pending".');
|
console.log('Overdue tasks updated to "Pending".');
|
||||||
} catch (error) {
|
} 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
|
// Schedule the cron job to run daily at midnight
|
||||||
cron.schedule('0 0 * * *', updateOverdueTasks);
|
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 parseDate = (dateStr) => {
|
||||||
const [day, month, year] = dateStr.split('/').map(Number);
|
const [day, month, year] = dateStr.split("/").map(Number);
|
||||||
return new Date(year, month - 1, day);
|
// 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) => {
|
export const assignTask = async (req, res) => {
|
||||||
@ -51,10 +57,10 @@ export const assignTask = async (req, res) => {
|
|||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
|
|
||||||
// Set the time of the currentDate to the start of the day for comparison
|
// 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
|
// Check if the due date is in the past
|
||||||
if (dueDate < currentDate) {
|
if (dueDate < currentDateOnly) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: "Due date cannot be earlier than the current date.",
|
message: "Due date cannot be earlier than the current date.",
|
||||||
@ -128,7 +134,14 @@ export const getTasksbytask = async (req, res) => {
|
|||||||
const { task } = req.params;
|
const { task } = req.params;
|
||||||
|
|
||||||
// Validate the provided status
|
// 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({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: "Invalid task type provided.",
|
message: "Invalid task type provided.",
|
||||||
@ -154,7 +167,10 @@ export const updateTaskStatus = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const { taskId } = req.params;
|
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) {
|
if (!task) {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
|
Loading…
Reference in New Issue
Block a user