|
|
|
@ -7645,3 +7645,71 @@ exports.updateComments = async (req, reply) => {
|
|
|
|
|
return reply.code(500).send({ error: "Internal server error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.resolvedIssuesForSupport = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { supportId } = req.params;
|
|
|
|
|
|
|
|
|
|
if (!supportId) {
|
|
|
|
|
return reply.code(400).send({ error: "supportId is required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch support document
|
|
|
|
|
const support = await Support.findOne({ supportId });
|
|
|
|
|
if (!support) {
|
|
|
|
|
return reply.code(404).send({ error: "Support record not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const categorizedIssues = support.categorizedIssues || [];
|
|
|
|
|
const resolvedIssues = support.resolvedIssues || [];
|
|
|
|
|
let updatedCount = 0;
|
|
|
|
|
|
|
|
|
|
// Filter escalation issues
|
|
|
|
|
const escalationIssues = categorizedIssues.filter(issue => issue.category === "Escalation");
|
|
|
|
|
|
|
|
|
|
for (const issue of escalationIssues) {
|
|
|
|
|
const masterHardwareId = issue.masterHardwareId || issue.hardwareId;
|
|
|
|
|
|
|
|
|
|
// Get master sensor
|
|
|
|
|
const master = await Insensors.findOne({ hardwareId: masterHardwareId }).lean();
|
|
|
|
|
if (!master) continue;
|
|
|
|
|
|
|
|
|
|
// Get slaves connected to this master
|
|
|
|
|
const slaves = await Insensors.find({ connected_to: masterHardwareId }).lean();
|
|
|
|
|
|
|
|
|
|
// Check if master and all slaves are connected
|
|
|
|
|
const allConnected = master.connected_status === "connected" && slaves.every(s => s.connected_status === "connected");
|
|
|
|
|
|
|
|
|
|
if (allConnected) {
|
|
|
|
|
// Prepare resolved issue data
|
|
|
|
|
const resolvedIssue = {
|
|
|
|
|
...issue.toObject ? issue.toObject() : issue, // convert if mongoose doc
|
|
|
|
|
category: "Resolved",
|
|
|
|
|
resolvedAt: new Date().toISOString(),
|
|
|
|
|
originalMovedAt: issue.movedAt || null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Remove from categorizedIssues
|
|
|
|
|
support.categorizedIssues = support.categorizedIssues.filter(i => i._id.toString() !== issue._id.toString());
|
|
|
|
|
|
|
|
|
|
// Add to resolvedIssues
|
|
|
|
|
support.resolvedIssues.push(resolvedIssue);
|
|
|
|
|
|
|
|
|
|
updatedCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save updated support document
|
|
|
|
|
await support.save();
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
status: "success",
|
|
|
|
|
message: `${updatedCount} issue(s) moved to resolved`,
|
|
|
|
|
supportId,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error in updateIssueResolutionBasedOnConnectionStatus:", error);
|
|
|
|
|
return reply.code(500).send({ error: "Internal server error" });
|
|
|
|
|
}
|
|
|
|
|
}
|