master^2
Bhaskar 5 months ago
parent 787cdc1e7d
commit 6ca57eaf45

@ -4217,23 +4217,19 @@ exports.particularCategory = async (req, 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
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;

@ -270,6 +270,8 @@ const installationschema = new mongoose.Schema({
support_teamMemberId: String,
phone: String,
email: String,
startDate: String,
endDate: String
}
}
],

@ -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,10 +716,13 @@ 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" },
},
},
},

Loading…
Cancel
Save