|
|
@ -4217,23 +4217,19 @@ exports.particularCategory = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.assignCategorizeIssue = async (request, reply) => {
|
|
|
|
exports.assignCategorizeIssue = async (request, reply) => {
|
|
|
|
const { supportId } = request.params;
|
|
|
|
const { supportId } = request.params;
|
|
|
|
const { categorizedIssueId, support_teamMemberId } = request.body;
|
|
|
|
const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
if (!categorizedIssueId || !support_teamMemberId) {
|
|
|
|
if (!support_teamMemberId || !startDate || !endDate || !category || !masterHardwareId) {
|
|
|
|
return reply.code(400).send({ error: 'categorizedIssueId and support_teamMemberId are required' });
|
|
|
|
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 });
|
|
|
|
const support = await Support.findOne({ supportId });
|
|
|
|
if (!support) {
|
|
|
|
if (!support) {
|
|
|
|
return reply.code(404).send({ error: 'Support record not found' });
|
|
|
|
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 teamMembers = support.team_member?.team_member || [];
|
|
|
|
const teamMember = teamMembers.find(m => m.support_teamMemberId === support_teamMemberId);
|
|
|
|
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` });
|
|
|
|
return reply.code(400).send({ error: `Team member ID ${support_teamMemberId} not found` });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Find the categorized issue to assign
|
|
|
|
const start = new Date(startDate);
|
|
|
|
const issue = support.categorizedIssues.id(categorizedIssueId);
|
|
|
|
const end = new Date(endDate);
|
|
|
|
if (!issue) {
|
|
|
|
if (isNaN(start) || isNaN(end)) {
|
|
|
|
return reply.code(404).send({ error: `Categorized issue with ID ${categorizedIssueId} not found` });
|
|
|
|
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 = {
|
|
|
|
issue.assignedTo = {
|
|
|
|
name: teamMember.name,
|
|
|
|
name: teamMember.name,
|
|
|
|
support_teamMemberId: teamMember.support_teamMemberId,
|
|
|
|
support_teamMemberId: teamMember.support_teamMemberId,
|
|
|
|
phone: teamMember.phone,
|
|
|
|
phone: teamMember.phone,
|
|
|
|
email: teamMember.email,
|
|
|
|
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();
|
|
|
|
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) => {
|
|
|
|
exports.getCategorizedIssue = async (request, reply) => {
|
|
|
|
const { support_teamMemberId } = request.params;
|
|
|
|
const { support_teamMemberId } = request.params;
|
|
|
|
|
|
|
|
|
|
|
|