|
|
|
@ -6080,171 +6080,70 @@ exports.updateHardwareList = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.assignCategorizeIssue = async (request, reply) => {
|
|
|
|
|
// const { supportId } = request.params;
|
|
|
|
|
// const { support_teamMemberId, category, masterHardwareId } = request.body;
|
|
|
|
|
|
|
|
|
|
// if (!support_teamMemberId || !category || !masterHardwareId) {
|
|
|
|
|
// return reply.code(400).send({
|
|
|
|
|
// error: 'support_teamMemberId, category, and masterHardwareId are required'
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const support = await Support.findOne({ supportId });
|
|
|
|
|
// if (!support) {
|
|
|
|
|
// return reply.code(404).send({ error: 'Support record not found' });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 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` });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const assignedAt = moment().format("DD-MM-YYYY HH:mm:ss");
|
|
|
|
|
// const assignmentCode = Math.floor(100000 + Math.random() * 900000).toString(); // random 6-digit code
|
|
|
|
|
// let assignedCount = 0;
|
|
|
|
|
|
|
|
|
|
// support.categorizedIssues.forEach(issue => {
|
|
|
|
|
// if (
|
|
|
|
|
// issue.masterHardwareId === masterHardwareId &&
|
|
|
|
|
// issue.category === category
|
|
|
|
|
// ) {
|
|
|
|
|
// issue.assignedTo = {
|
|
|
|
|
// name: teamMember.name,
|
|
|
|
|
// support_teamMemberId: teamMember.support_teamMemberId,
|
|
|
|
|
// phone: teamMember.phone,
|
|
|
|
|
// email: teamMember.email,
|
|
|
|
|
// assignedAt: assignedAt,
|
|
|
|
|
// assignmentCode: assignmentCode // ← Add this field
|
|
|
|
|
// };
|
|
|
|
|
// assignedCount++;
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// if (assignedCount === 0) {
|
|
|
|
|
// return reply.code(404).send({ message: 'No matching issues found for assignment' });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// await support.save();
|
|
|
|
|
|
|
|
|
|
// return reply.send({
|
|
|
|
|
// message: `Assigned ${assignedCount} categorized issue(s) to ${teamMember.name}`,
|
|
|
|
|
// assignmentCode: assignmentCode, // ← Return the code in response
|
|
|
|
|
// assignedTo: {
|
|
|
|
|
// support_teamMemberId: teamMember.support_teamMemberId,
|
|
|
|
|
// name: teamMember.name,
|
|
|
|
|
// phone: teamMember.phone,
|
|
|
|
|
// email: teamMember.email,
|
|
|
|
|
// assignedAt: assignedAt,
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.assignCategorizeIssue = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { supportId } = request.params;
|
|
|
|
|
const { support_teamMemberId, quationId } = request.body;
|
|
|
|
|
const { supportId } = request.params;
|
|
|
|
|
const { support_teamMemberId, category, masterHardwareId } = request.body;
|
|
|
|
|
|
|
|
|
|
// Step 1: Validate input
|
|
|
|
|
if (!supportId || !support_teamMemberId || !quationId) {
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
error: 'supportId (path), support_teamMemberId, and quationId (body) are required'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!support_teamMemberId || !category || !masterHardwareId) {
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
error: 'support_teamMemberId, category, and masterHardwareId are required'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 2: Find support record
|
|
|
|
|
const support = await Support.findOne({ supportId });
|
|
|
|
|
if (!support) {
|
|
|
|
|
return reply.code(404).send({ error: 'Support record not found' });
|
|
|
|
|
}
|
|
|
|
|
const support = await Support.findOne({ supportId });
|
|
|
|
|
if (!support) {
|
|
|
|
|
return reply.code(404).send({ error: 'Support record not found' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 3: Check team member exists
|
|
|
|
|
const teamMembers = support.team_member?.team_member || [];
|
|
|
|
|
const teamMember = teamMembers.find(m => m.support_teamMemberId === support_teamMemberId);
|
|
|
|
|
const teamMembers = support.team_member?.team_member || [];
|
|
|
|
|
const teamMember = teamMembers.find(m => m.support_teamMemberId === support_teamMemberId);
|
|
|
|
|
|
|
|
|
|
if (!teamMember) {
|
|
|
|
|
return reply.code(404).send({ error: `Team member ID ${support_teamMemberId} not found` });
|
|
|
|
|
}
|
|
|
|
|
if (!teamMember) {
|
|
|
|
|
return reply.code(400).send({ error: `Team member ID ${support_teamMemberId} not found` });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 4: Assign all categorized issues
|
|
|
|
|
const assignedAt = moment().format("DD-MM-YYYY HH:mm:ss");
|
|
|
|
|
const assignmentCode = Math.floor(100000 + Math.random() * 900000).toString(); // random 6-digit code
|
|
|
|
|
let assignedCount = 0;
|
|
|
|
|
const assignedAt = moment().format("DD-MM-YYYY HH:mm:ss");
|
|
|
|
|
const assignmentCode = Math.floor(100000 + Math.random() * 900000).toString(); // random 6-digit code
|
|
|
|
|
let assignedCount = 0;
|
|
|
|
|
|
|
|
|
|
support.issues.forEach(issue => {
|
|
|
|
|
support.categorizedIssues.forEach(issue => {
|
|
|
|
|
if (
|
|
|
|
|
issue.masterHardwareId === masterHardwareId &&
|
|
|
|
|
issue.category === category
|
|
|
|
|
) {
|
|
|
|
|
issue.assignedTo = {
|
|
|
|
|
name: teamMember.name,
|
|
|
|
|
support_teamMemberId: teamMember.support_teamMemberId,
|
|
|
|
|
phone: teamMember.phone,
|
|
|
|
|
email: teamMember.email,
|
|
|
|
|
assignedAt: assignedAt,
|
|
|
|
|
assignmentCode: assignmentCode,
|
|
|
|
|
quationId: quationId
|
|
|
|
|
assignmentCode: assignmentCode // ← Add this field
|
|
|
|
|
};
|
|
|
|
|
assignedCount++;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (assignedCount === 0) {
|
|
|
|
|
return reply.code(404).send({ message: 'No categorized issues found to assign' });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Step 5: Save support document
|
|
|
|
|
await support.save();
|
|
|
|
|
|
|
|
|
|
// Step 6: Update or create the Order document with assigned support team member
|
|
|
|
|
let order = await Order.findOne({ quatationId: quationId });
|
|
|
|
|
if (assignedCount === 0) {
|
|
|
|
|
return reply.code(404).send({ message: 'No matching issues found for assignment' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!order) {
|
|
|
|
|
order = new Order({
|
|
|
|
|
quatationId: quationId,
|
|
|
|
|
assignedTeamMembers: [],
|
|
|
|
|
quatation_status: "Assigned",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
await support.save();
|
|
|
|
|
|
|
|
|
|
// Save the assigned support team member info
|
|
|
|
|
order.assignedSupportTeamMember = {
|
|
|
|
|
return reply.send({
|
|
|
|
|
message: `Assigned ${assignedCount} categorized issue(s) to ${teamMember.name}`,
|
|
|
|
|
assignmentCode: assignmentCode, // ← Return the code in response
|
|
|
|
|
assignedTo: {
|
|
|
|
|
support_teamMemberId: teamMember.support_teamMemberId,
|
|
|
|
|
name: teamMember.name,
|
|
|
|
|
phone: teamMember.phone,
|
|
|
|
|
email: teamMember.email,
|
|
|
|
|
assignedAt: assignedAt,
|
|
|
|
|
assignmentCode: assignmentCode,
|
|
|
|
|
quationId: quationId,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await order.save();
|
|
|
|
|
|
|
|
|
|
// Step 7: Return response
|
|
|
|
|
return reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
message: `Assigned ${assignedCount} categorized issue(s) to ${teamMember.name}`,
|
|
|
|
|
assignmentCode: assignmentCode,
|
|
|
|
|
assignedTo: {
|
|
|
|
|
support_teamMemberId: teamMember.support_teamMemberId,
|
|
|
|
|
name: teamMember.name,
|
|
|
|
|
phone: teamMember.phone,
|
|
|
|
|
email: teamMember.email,
|
|
|
|
|
assignedAt: assignedAt,
|
|
|
|
|
quationId: quationId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error assigning categorized issues:", error);
|
|
|
|
|
return reply.status(500).send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: true,
|
|
|
|
|
message: "Internal Server Error"
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getCategorizedIssue = async (request, reply) => {
|
|
|
|
|