|
|
|
@ -3912,3 +3912,112 @@ exports.deleteTeamMemberSupport = async (req, reply)=> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.moveIssueToCategory = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { supportId, category } = req.body;
|
|
|
|
|
|
|
|
const { hardwareId, tankhardwareId } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!supportId || !category || (!hardwareId && !tankhardwareId)) {
|
|
|
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
|
|
|
message: "supportId, category, and hardwareId or tankhardwareId are required",
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const support = await Support.findOne({ supportId });
|
|
|
|
|
|
|
|
if (!support) {
|
|
|
|
|
|
|
|
return reply.code(404).send({ message: "Support record not found" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let issueMoved = false;
|
|
|
|
|
|
|
|
const nowTime = moment().tz("Asia/Kolkata").format("YYYY-MM-DD HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure categorizedIssues array exists
|
|
|
|
|
|
|
|
if (!Array.isArray(support.categorizedIssues)) {
|
|
|
|
|
|
|
|
support.categorizedIssues = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Master Issue Move
|
|
|
|
|
|
|
|
if (hardwareId && !tankhardwareId) {
|
|
|
|
|
|
|
|
const index = support.issues.findIndex(
|
|
|
|
|
|
|
|
(issue) => issue.hardwareId === hardwareId && issue.masterHardwareId === hardwareId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
|
|
|
const issue = support.issues[index];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
support.categorizedIssues.push({
|
|
|
|
|
|
|
|
...issue,
|
|
|
|
|
|
|
|
category,
|
|
|
|
|
|
|
|
movedAt: nowTime,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
support.issues.splice(index, 1);
|
|
|
|
|
|
|
|
issueMoved = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Slave Issue Move
|
|
|
|
|
|
|
|
if (tankhardwareId) {
|
|
|
|
|
|
|
|
for (let i = 0; i < support.issues.length; i++) {
|
|
|
|
|
|
|
|
const issue = support.issues[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const slaveIndex = issue.hardwareIds?.indexOf(tankhardwareId);
|
|
|
|
|
|
|
|
if (slaveIndex !== -1) {
|
|
|
|
|
|
|
|
const slaveName = issue.slaveNames?.[slaveIndex] || "Unknown";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add to categorized issues
|
|
|
|
|
|
|
|
support.categorizedIssues.push({
|
|
|
|
|
|
|
|
type: issue.type,
|
|
|
|
|
|
|
|
hardwareId: tankhardwareId,
|
|
|
|
|
|
|
|
masterHardwareId: issue.masterHardwareId,
|
|
|
|
|
|
|
|
slaveName,
|
|
|
|
|
|
|
|
category,
|
|
|
|
|
|
|
|
movedAt: nowTime,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove from current issue
|
|
|
|
|
|
|
|
issue.hardwareIds.splice(slaveIndex, 1);
|
|
|
|
|
|
|
|
issue.slaveNames.splice(slaveIndex, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove issue completely if no more slaves
|
|
|
|
|
|
|
|
if (issue.hardwareIds.length === 0) {
|
|
|
|
|
|
|
|
support.issues.splice(i, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
issueMoved = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (issueMoved) {
|
|
|
|
|
|
|
|
await support.save();
|
|
|
|
|
|
|
|
return reply.send({ message: "Issue moved to category successfully" });
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return reply.code(404).send({ message: "No matching issue found to move" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error("Error moving issue:", err);
|
|
|
|
|
|
|
|
return reply.code(500).send({ error: "Internal Server Error" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.particularCategory = async (req, reply) => {
|
|
|
|
|
|
|
|
const { supportId, category } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const support = await Support.findOne({ supportId });
|
|
|
|
|
|
|
|
if (!support) {
|
|
|
|
|
|
|
|
return reply.code(404).send({ message: 'Support record not found' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const issues = (support.categorizedIssues || []).filter(
|
|
|
|
|
|
|
|
(issue) => issue.category === category
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (issues.length === 0) {
|
|
|
|
|
|
|
|
return reply.code(404).send({ message: `No issues found for category: ${category}` });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({ category, issues });
|
|
|
|
|
|
|
|
};
|
|
|
|
|