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 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({
|
||||
|
Loading…
Reference in New Issue
Block a user