task update
This commit is contained in:
parent
6e21d07fb6
commit
932fb7cb2a
@ -178,6 +178,12 @@ export const getAllSalesCoOrdinator = async (req, res) => {
|
||||
try {
|
||||
const PAGE_SIZE = parseInt(req.query?.show || "10");
|
||||
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 = {};
|
||||
if (req.query?.name) {
|
||||
filter.name = {
|
||||
@ -192,7 +198,8 @@ export const getAllSalesCoOrdinator = async (req, res) => {
|
||||
if (req.query?.isVerified) {
|
||||
filter.isVerified = req.query.isVerified === "true";
|
||||
}
|
||||
|
||||
// Mandatory filter for mappedby
|
||||
filter.mappedby = req.user._id;
|
||||
const total = await SalesCoOrdinator.countDocuments(filter);
|
||||
const salesCoOrinators = await SalesCoOrdinator.find(filter)
|
||||
.limit(PAGE_SIZE)
|
||||
|
@ -26,8 +26,8 @@ const updateOverdueTasks = async () => {
|
||||
};
|
||||
|
||||
// Schedule the cron job to run daily at midnight
|
||||
cron.schedule('16 9 * * *', updateOverdueTasks, {
|
||||
timezone: "Asia/Kolkata"
|
||||
cron.schedule("10 0 * * *", updateOverdueTasks, {
|
||||
timezone: "Asia/Kolkata",
|
||||
});
|
||||
|
||||
// cron.schedule("30 9 * * *", updateOverdueTasks);
|
||||
@ -58,7 +58,13 @@ export const assignTask = async (req, res) => {
|
||||
const currentDate = new Date();
|
||||
|
||||
// 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
|
||||
if (dueDate < currentDateOnly) {
|
||||
@ -100,7 +106,6 @@ export const assignTask = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const getTasksByStatus = async (req, res) => {
|
||||
try {
|
||||
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) => {
|
||||
try {
|
||||
const { task } = req.params;
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
getTasksByStatus,
|
||||
updateTaskStatus,
|
||||
getTasksbytask,
|
||||
getAllTasksByStatus,
|
||||
} from "./TaskController.js";
|
||||
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
|
||||
import { isAuthenticatedTerritoryManager } from "../../middlewares/TerritoryManagerAuth.js";
|
||||
@ -23,6 +24,11 @@ router.get(
|
||||
isAuthenticatedSalesCoOrdinator,
|
||||
getTasksByStatus
|
||||
);
|
||||
router.get(
|
||||
"/alltasks/:status",
|
||||
isAuthenticatedTerritoryManager,
|
||||
getAllTasksByStatus
|
||||
);
|
||||
router.get(
|
||||
"/task/type/:task",
|
||||
isAuthenticatedSalesCoOrdinator,
|
||||
|
Loading…
Reference in New Issue
Block a user