diff --git a/public/uploads/CHEMINOVA_APP_PD_AS_ON_17_10_24_TEST_01.xlsx b/public/uploads/CHEMINOVA_APP_PD_AS_ON_17_10_24_TEST_01.xlsx new file mode 100644 index 0000000..39b50ef Binary files /dev/null and b/public/uploads/CHEMINOVA_APP_PD_AS_ON_17_10_24_TEST_01.xlsx differ diff --git a/resources/ShippingAddresses/ShippingAddressModel.js b/resources/ShippingAddresses/ShippingAddressModel.js index 399c02d..18a401e 100644 --- a/resources/ShippingAddresses/ShippingAddressModel.js +++ b/resources/ShippingAddresses/ShippingAddressModel.js @@ -6,7 +6,7 @@ const shippingAddressSchema = new mongoose.Schema( type: String, }, phoneNumber: { - type: Number, + type: String, }, street: { type: String, diff --git a/resources/ShippingAddressesRD/RDShippingAddressModel.js b/resources/ShippingAddressesRD/RDShippingAddressModel.js index 8054fc0..759f1a4 100644 --- a/resources/ShippingAddressesRD/RDShippingAddressModel.js +++ b/resources/ShippingAddressesRD/RDShippingAddressModel.js @@ -6,7 +6,7 @@ const shippingAddressSchema = new mongoose.Schema( type: String, }, phoneNumber: { - type: Number, + type: String, }, street: { type: String, diff --git a/resources/Task/TaskController.js b/resources/Task/TaskController.js index a2c6f89..d7a8f77 100644 --- a/resources/Task/TaskController.js +++ b/resources/Task/TaskController.js @@ -384,27 +384,31 @@ export const getTodaysTasks = async (req, res) => { const skip = (currentPage - 1) * itemsPerPage; // Find tasks that are due today, with pagination - let tasksQuery = Task.find({ + const tasks = await Task.find({ taskDueDate: { $gte: startOfToday, $lte: endOfToday, }, }) - .populate('taskAssignedTo') // Optional: populate assigned coordinator details - .populate('taskAssignedBy') // Optional: populate assigned manager details + .populate("taskAssignedTo") // Optional: populate assigned coordinator details + .populate("taskAssignedBy") // Optional: populate assigned manager details .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 - tasksQuery = tasksQuery.populate({ - path: 'addedForId', - model: function (doc) { - return doc.addedFor === 'PrincipalDistributor' ? 'User' : 'RetailDistributor'; - }, - }); - - // Execute the query - const tasks = await tasksQuery.exec(); + // Populate addedForId conditionally + const populatedTasks = await Promise.all( + tasks.map(async (task) => { + if (task.addedFor === "PrincipalDistributor") { + // Populate with PrincipalDistributor + await task.populate("addedForId", User); + } else if (task.addedFor === "RetailDistributor") { + // Populate with RetailDistributor + await task.populate("addedForId", RetailDistributor); + } + return task; // Return the populated task + }) + ); // Count the total number of tasks for pagination metadata const totalTasks = await Task.countDocuments({ @@ -419,14 +423,14 @@ export const getTodaysTasks = async (req, res) => { // Send paginated tasks in response res.status(200).json({ - tasks, // Paginated tasks + tasks: populatedTasks, // Paginated and populated tasks currentPage, // Current page number itemsPerPage, // Number of tasks per page totalTasks, // Total number of tasks totalPages, // Total number of pages }); } catch (error) { - console.error('Error fetching today\'s tasks with pagination:', error); - res.status(500).json({ message: 'Failed to retrieve tasks for today' }); + console.error("Error fetching today's tasks with pagination:", error); + res.status(500).json({ message: "Failed to retrieve tasks for today" }); } -}; \ No newline at end of file +}; diff --git a/resources/user/userController.js b/resources/user/userController.js index 4a51f07..34c3162 100644 --- a/resources/user/userController.js +++ b/resources/user/userController.js @@ -553,7 +553,7 @@ export const uploadPrincipaldistributors = async (req, res) => { // Check for changes in address details const addressData = { Name: item.name, - phoneNumber: item.phone.toString(), + phoneNumber: item.phone.toString().trim(), street: item.street, city: item.city, state: item.state, diff --git a/resources/user/userModel.js b/resources/user/userModel.js index d9ce78c..67d14a1 100644 --- a/resources/user/userModel.js +++ b/resources/user/userModel.js @@ -38,7 +38,6 @@ const userSchema = new mongoose.Schema( name: { type: String, required: [true, "Please Enter Your Name"], - maxLength: [30, "Name cannot exceed 30 characters"], }, email: { type: String,