task update
This commit is contained in:
parent
6e21d07fb6
commit
932fb7cb2a
@ -178,6 +178,12 @@ export const getAllSalesCoOrdinator = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const PAGE_SIZE = parseInt(req.query?.show || "10");
|
const PAGE_SIZE = parseInt(req.query?.show || "10");
|
||||||
const page = parseInt(req.query?.page || "1") - 1;
|
const page = parseInt(req.query?.page || "1") - 1;
|
||||||
|
if (!req.user || !req.user._id) {
|
||||||
|
return res.status(401).json({
|
||||||
|
success: false,
|
||||||
|
message: "Please login to a TM account",
|
||||||
|
});
|
||||||
|
}
|
||||||
let filter = {};
|
let filter = {};
|
||||||
if (req.query?.name) {
|
if (req.query?.name) {
|
||||||
filter.name = {
|
filter.name = {
|
||||||
@ -192,7 +198,8 @@ export const getAllSalesCoOrdinator = async (req, res) => {
|
|||||||
if (req.query?.isVerified) {
|
if (req.query?.isVerified) {
|
||||||
filter.isVerified = req.query.isVerified === "true";
|
filter.isVerified = req.query.isVerified === "true";
|
||||||
}
|
}
|
||||||
|
// Mandatory filter for mappedby
|
||||||
|
filter.mappedby = req.user._id;
|
||||||
const total = await SalesCoOrdinator.countDocuments(filter);
|
const total = await SalesCoOrdinator.countDocuments(filter);
|
||||||
const salesCoOrinators = await SalesCoOrdinator.find(filter)
|
const salesCoOrinators = await SalesCoOrdinator.find(filter)
|
||||||
.limit(PAGE_SIZE)
|
.limit(PAGE_SIZE)
|
||||||
|
@ -26,8 +26,8 @@ const updateOverdueTasks = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Schedule the cron job to run daily at midnight
|
// Schedule the cron job to run daily at midnight
|
||||||
cron.schedule('16 9 * * *', updateOverdueTasks, {
|
cron.schedule("10 0 * * *", updateOverdueTasks, {
|
||||||
timezone: "Asia/Kolkata"
|
timezone: "Asia/Kolkata",
|
||||||
});
|
});
|
||||||
|
|
||||||
// cron.schedule("30 9 * * *", updateOverdueTasks);
|
// cron.schedule("30 9 * * *", updateOverdueTasks);
|
||||||
@ -56,9 +56,15 @@ export const assignTask = async (req, res) => {
|
|||||||
// Convert the taskDueDate from DD/MM/YYYY string to Date object
|
// Convert the taskDueDate from DD/MM/YYYY string to Date object
|
||||||
const dueDate = parseDate(taskDueDate);
|
const dueDate = parseDate(taskDueDate);
|
||||||
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
|
||||||
const currentDateOnly = new Date(Date.UTC(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()));
|
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 < currentDateOnly) {
|
if (dueDate < currentDateOnly) {
|
||||||
@ -100,7 +106,6 @@ export const assignTask = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const getTasksByStatus = async (req, res) => {
|
export const getTasksByStatus = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { status } = req.params; // This should be "New", "Pending", or "Completed"
|
const { status } = req.params; // This should be "New", "Pending", or "Completed"
|
||||||
@ -130,6 +135,40 @@ export const getTasksByStatus = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const getAllTasksByStatus = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { status } = req.params; // This should be "New", "Pending", or "Completed"
|
||||||
|
|
||||||
|
// Validate the provided status
|
||||||
|
if (!["New", "Pending", "Completed"].includes(status)) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: "Invalid status type provided.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find tasks assigned to the user, filtered by status, and sorted by creation date (newest to oldest)
|
||||||
|
const tasks = await Task.find({
|
||||||
|
taskAssignedBy: req.user._id,
|
||||||
|
taskStatus: status,
|
||||||
|
})
|
||||||
|
.populate({
|
||||||
|
path: "taskAssignedTo",
|
||||||
|
select: "name mobileNumber email",
|
||||||
|
})
|
||||||
|
.sort({ createdAt: -1 }); // Sort by createdAt in descending order (-1 means newest first)
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
tasks,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
export const getTasksbytask = async (req, res) => {
|
export const getTasksbytask = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { task } = req.params;
|
const { task } = req.params;
|
||||||
|
@ -4,6 +4,7 @@ import {
|
|||||||
getTasksByStatus,
|
getTasksByStatus,
|
||||||
updateTaskStatus,
|
updateTaskStatus,
|
||||||
getTasksbytask,
|
getTasksbytask,
|
||||||
|
getAllTasksByStatus,
|
||||||
} from "./TaskController.js";
|
} from "./TaskController.js";
|
||||||
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
|
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
|
||||||
import { isAuthenticatedTerritoryManager } from "../../middlewares/TerritoryManagerAuth.js";
|
import { isAuthenticatedTerritoryManager } from "../../middlewares/TerritoryManagerAuth.js";
|
||||||
@ -23,6 +24,11 @@ router.get(
|
|||||||
isAuthenticatedSalesCoOrdinator,
|
isAuthenticatedSalesCoOrdinator,
|
||||||
getTasksByStatus
|
getTasksByStatus
|
||||||
);
|
);
|
||||||
|
router.get(
|
||||||
|
"/alltasks/:status",
|
||||||
|
isAuthenticatedTerritoryManager,
|
||||||
|
getAllTasksByStatus
|
||||||
|
);
|
||||||
router.get(
|
router.get(
|
||||||
"/task/type/:task",
|
"/task/type/:task",
|
||||||
isAuthenticatedSalesCoOrdinator,
|
isAuthenticatedSalesCoOrdinator,
|
||||||
|
Loading…
Reference in New Issue
Block a user