diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index bba91fd4..f81b26ba 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -4216,3 +4216,46 @@ exports.particularCategory = async (req, reply) => { return reply.code(500).send({ error: "Internal server error" }); } }; + + +exports.assignCategorizeIssue = async (request, reply) => { + const { supportId } = request.params; + const { categorizedIssueId, support_teamMemberId } = request.body; + + if (!categorizedIssueId || !support_teamMemberId) { + return reply.code(400).send({ error: 'categorizedIssueId and support_teamMemberId 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); + + if (!teamMember) { + 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` }); + } + + // Assign the team member info to the issue + issue.assignedTo = { + name: teamMember.name, + support_teamMemberId: teamMember.support_teamMemberId, + phone: teamMember.phone, + email: teamMember.email, + }; + + await support.save(); + + return reply.send({ message: 'Issue assigned successfully', issue }); +}; diff --git a/src/models/store.js b/src/models/store.js index 8adad09a..9ea4c9bb 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -264,7 +264,13 @@ const installationschema = new mongoose.Schema({ movedAt: { type: String, // or Date, depending on your preference required: true - } + }, + assignedTo: { + name: String, + support_teamMemberId: String, + phone: String, + email: String, + } } ], diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 68842a00..4460221c 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -702,7 +702,29 @@ module.exports = function (fastify, opts, next) { }); - + fastify.post("/api/assignTeamMemberIssueToCategory/:supportId", { + schema: { + description: "Assign the team member categorize issue", + tags: ["Support"], + summary: "Assign the team member categorize issue", + params: { + type: "object", + required: ["supportId"], + properties: { + supportId: { type: "string" }, + }, + }, + body: { + type: "object", + required: ["categorizedIssueId", "support_teamMemberId"], + properties: { + categorizedIssueId: { type: "string" }, + support_teamMemberId: { type: "string" }, + }, + }, + }, + handler: installationController.assignCategorizeIssue + }); next(); } \ No newline at end of file