From 6ca57eaf4555ddbdec691b7cb3961f00e74ddcb4 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Tue, 20 May 2025 18:31:54 +0530 Subject: [PATCH] changes --- src/controllers/installationController.js | 57 +++++++++++++++-------- src/models/store.js | 2 + src/routes/installationRoute.js | 13 ++++-- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 9d57ac97..6d7ecf9c 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -4217,23 +4217,19 @@ exports.particularCategory = async (req, reply) => { } }; - -exports.assignCategorizeIssue = async (request, reply) => { +exports.assignCategorizeIssue = async (request, reply) => { const { supportId } = request.params; - const { categorizedIssueId, support_teamMemberId } = request.body; + const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body; - if (!categorizedIssueId || !support_teamMemberId) { - return reply.code(400).send({ error: 'categorizedIssueId and support_teamMemberId are required' }); + if (!support_teamMemberId || !startDate || !endDate || !category || !masterHardwareId) { + return reply.code(400).send({ error: 'support_teamMemberId, startDate, endDate, category, and masterHardwareId are required' }); } - //const Support = Support.model('Support'); // your model name here - const support = await Support.findOne({ supportId }); if (!support) { return reply.code(404).send({ error: 'Support record not found' }); } - // Find the team member in the support team_member array const teamMembers = support.team_member?.team_member || []; const teamMember = teamMembers.find(m => m.support_teamMemberId === support_teamMemberId); @@ -4241,26 +4237,47 @@ exports.assignCategorizeIssue = async (request, reply) => { return reply.code(400).send({ error: `Team member ID ${support_teamMemberId} not found` }); } - // Find the categorized issue to assign - const issue = support.categorizedIssues.id(categorizedIssueId); - if (!issue) { - return reply.code(404).send({ error: `Categorized issue with ID ${categorizedIssueId} not found` }); + const start = new Date(startDate); + const end = new Date(endDate); + if (isNaN(start) || isNaN(end)) { + return reply.code(400).send({ error: 'Invalid startDate or endDate' }); } - // Assign the team member info to the issue - issue.assignedTo = { - name: teamMember.name, - support_teamMemberId: teamMember.support_teamMemberId, - phone: teamMember.phone, - email: teamMember.email, - }; + let assignedCount = 0; + + support.categorizedIssues.forEach(issue => { + const issueDate = new Date(issue.movedAt); + if ( + issue.masterHardwareId === masterHardwareId && + issue.category === category + ) { + issue.assignedTo = { + name: teamMember.name, + support_teamMemberId: teamMember.support_teamMemberId, + phone: teamMember.phone, + email: teamMember.email, + startDate: startDate, // Add startDate + endDate: endDate // Add endDate + }; + assignedCount++; + } + }); + + if (assignedCount === 0) { + return reply.code(404).send({ message: 'No matching issues found for assignment' }); + } await support.save(); - return reply.send({ message: 'Issue assigned successfully', issue }); + return reply.send({ + message: `Assigned ${assignedCount} categorized issue(s) to ${teamMember.name}`, + assignedTo: teamMember.support_teamMemberId + }); }; + + exports.getCategorizedIssue = async (request, reply) => { const { support_teamMemberId } = request.params; diff --git a/src/models/store.js b/src/models/store.js index 9ea4c9bb..6711c69d 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -270,6 +270,8 @@ const installationschema = new mongoose.Schema({ support_teamMemberId: String, phone: String, email: String, + startDate: String, + endDate: String } } ], diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index a4629a5d..36226769 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -704,9 +704,9 @@ module.exports = function (fastify, opts, next) { fastify.post("/api/assignTeamMemberIssueToCategory/:supportId", { schema: { - description: "Assign the team member categorize issue", + description: "Assign a team member to a categorized issue", tags: ["Support"], - summary: "Assign the team member categorize issue", + summary: "Assign a team member to a categorized issue", params: { type: "object", required: ["supportId"], @@ -716,16 +716,19 @@ module.exports = function (fastify, opts, next) { }, body: { type: "object", - required: ["categorizedIssueId", "support_teamMemberId"], + //required: [ "support_teamMemberId", "startDate", "endDate", "category", "masterHardwareId"], properties: { - categorizedIssueId: { type: "string" }, support_teamMemberId: { type: "string" }, + startDate: { type: "string", format: "date-time" }, + endDate: { type: "string", format: "date-time" }, + category: { type: "string" }, + masterHardwareId: { type: "string" }, }, }, }, handler: installationController.assignCategorizeIssue }); - + fastify.post("/api/my-categorized-issues/:support_teamMemberId", { schema: {