add multiple pd update
This commit is contained in:
parent
d4ad02de6a
commit
88496fb9d0
BIN
public/uploads/CHEMINOVA_APP_PD_AS_ON_17_10_24_TEST_01.xlsx
Normal file
BIN
public/uploads/CHEMINOVA_APP_PD_AS_ON_17_10_24_TEST_01.xlsx
Normal file
Binary file not shown.
@ -6,7 +6,7 @@ const shippingAddressSchema = new mongoose.Schema(
|
|||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
phoneNumber: {
|
phoneNumber: {
|
||||||
type: Number,
|
type: String,
|
||||||
},
|
},
|
||||||
street: {
|
street: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -6,7 +6,7 @@ const shippingAddressSchema = new mongoose.Schema(
|
|||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
phoneNumber: {
|
phoneNumber: {
|
||||||
type: Number,
|
type: String,
|
||||||
},
|
},
|
||||||
street: {
|
street: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -384,27 +384,31 @@ export const getTodaysTasks = async (req, res) => {
|
|||||||
const skip = (currentPage - 1) * itemsPerPage;
|
const skip = (currentPage - 1) * itemsPerPage;
|
||||||
|
|
||||||
// Find tasks that are due today, with pagination
|
// Find tasks that are due today, with pagination
|
||||||
let tasksQuery = Task.find({
|
const tasks = await Task.find({
|
||||||
taskDueDate: {
|
taskDueDate: {
|
||||||
$gte: startOfToday,
|
$gte: startOfToday,
|
||||||
$lte: endOfToday,
|
$lte: endOfToday,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.populate('taskAssignedTo') // Optional: populate assigned coordinator details
|
.populate("taskAssignedTo") // Optional: populate assigned coordinator details
|
||||||
.populate('taskAssignedBy') // Optional: populate assigned manager details
|
.populate("taskAssignedBy") // Optional: populate assigned manager details
|
||||||
.skip(skip) // Skip documents for pagination
|
.skip(skip) // Skip documents for pagination
|
||||||
.limit(itemsPerPage); // Limit the number of documents
|
.limit(itemsPerPage) // Limit the number of documents
|
||||||
|
.exec();
|
||||||
|
|
||||||
// Modify the population based on the `addedFor` field value
|
// Populate addedForId conditionally
|
||||||
tasksQuery = tasksQuery.populate({
|
const populatedTasks = await Promise.all(
|
||||||
path: 'addedForId',
|
tasks.map(async (task) => {
|
||||||
model: function (doc) {
|
if (task.addedFor === "PrincipalDistributor") {
|
||||||
return doc.addedFor === 'PrincipalDistributor' ? 'User' : 'RetailDistributor';
|
// Populate with PrincipalDistributor
|
||||||
},
|
await task.populate("addedForId", User);
|
||||||
});
|
} else if (task.addedFor === "RetailDistributor") {
|
||||||
|
// Populate with RetailDistributor
|
||||||
// Execute the query
|
await task.populate("addedForId", RetailDistributor);
|
||||||
const tasks = await tasksQuery.exec();
|
}
|
||||||
|
return task; // Return the populated task
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// Count the total number of tasks for pagination metadata
|
// Count the total number of tasks for pagination metadata
|
||||||
const totalTasks = await Task.countDocuments({
|
const totalTasks = await Task.countDocuments({
|
||||||
@ -419,14 +423,14 @@ export const getTodaysTasks = async (req, res) => {
|
|||||||
|
|
||||||
// Send paginated tasks in response
|
// Send paginated tasks in response
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
tasks, // Paginated tasks
|
tasks: populatedTasks, // Paginated and populated tasks
|
||||||
currentPage, // Current page number
|
currentPage, // Current page number
|
||||||
itemsPerPage, // Number of tasks per page
|
itemsPerPage, // Number of tasks per page
|
||||||
totalTasks, // Total number of tasks
|
totalTasks, // Total number of tasks
|
||||||
totalPages, // Total number of pages
|
totalPages, // Total number of pages
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching today\'s tasks with pagination:', error);
|
console.error("Error fetching today's tasks with pagination:", error);
|
||||||
res.status(500).json({ message: 'Failed to retrieve tasks for today' });
|
res.status(500).json({ message: "Failed to retrieve tasks for today" });
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -553,7 +553,7 @@ export const uploadPrincipaldistributors = async (req, res) => {
|
|||||||
// Check for changes in address details
|
// Check for changes in address details
|
||||||
const addressData = {
|
const addressData = {
|
||||||
Name: item.name,
|
Name: item.name,
|
||||||
phoneNumber: item.phone.toString(),
|
phoneNumber: item.phone.toString().trim(),
|
||||||
street: item.street,
|
street: item.street,
|
||||||
city: item.city,
|
city: item.city,
|
||||||
state: item.state,
|
state: item.state,
|
||||||
|
@ -38,7 +38,6 @@ const userSchema = new mongoose.Schema(
|
|||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
required: [true, "Please Enter Your Name"],
|
required: [true, "Please Enter Your Name"],
|
||||||
maxLength: [30, "Name cannot exceed 30 characters"],
|
|
||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
type: String,
|
type: String,
|
||||||
|
Loading…
Reference in New Issue
Block a user