long term issues move to isseus category

master^2
Bhaskar 3 months ago
parent 48bf0dac5a
commit 9ae37f55ae

@ -9126,20 +9126,19 @@ exports.moveIssueToCategory = async (req, reply) => {
let issueMoved = false; let issueMoved = false;
const nowTime = moment().tz("Asia/Kolkata").format("YYYY-MM-DD HH:mm:ss"); const nowTime = moment().tz("Asia/Kolkata").format("YYYY-MM-DD HH:mm:ss");
// Ensure categorizedIssues exists
if (!Array.isArray(support.categorizedIssues)) { if (!Array.isArray(support.categorizedIssues)) {
support.categorizedIssues = []; support.categorizedIssues = [];
} }
// Step 1: Try moving from support.issues (original logic)
const index = support.issues.findIndex((issue) => { const index = support.issues.findIndex((issue) => {
if (issue.hardwareId === hardwareId) return true; if (issue.hardwareId === hardwareId) return true;
if (Array.isArray(issue.hardwareIds) && issue.hardwareIds.includes(hardwareId)) return true; if (Array.isArray(issue.hardwareIds) && issue.hardwareIds.includes(hardwareId)) return true;
return false; return false;
}); });
if (index === -1) { if (index !== -1) {
return reply.code(404).send({ message: "No matching issue found to move" });
}
const issue = support.issues[index]; const issue = support.issues[index];
// Normalize type if needed // Normalize type if needed
@ -9180,7 +9179,6 @@ exports.moveIssueToCategory = async (req, reply) => {
issue.hardwareIds.splice(slaveIndex, 1); issue.hardwareIds.splice(slaveIndex, 1);
issue.slaveNames.splice(slaveIndex, 1); issue.slaveNames.splice(slaveIndex, 1);
// Remove full issue if no more slaves are left
if (issue.hardwareIds.length === 0) { if (issue.hardwareIds.length === 0) {
support.issues.splice(index, 1); support.issues.splice(index, 1);
} }
@ -9188,11 +9186,25 @@ exports.moveIssueToCategory = async (req, reply) => {
issueMoved = true; issueMoved = true;
} }
} }
}
if (issueMoved) { // Step 2: If not found in support.issues, try to update existing categorized issue
if (!issueMoved) {
const categorized = support.categorizedIssues.find(
(i) => i.hardwareId === hardwareId
);
if (categorized) {
categorized.category = category;
categorized.movedAt = nowTime;
await support.save(); await support.save();
return reply.send({ message: "Category updated for already categorized issue" });
}
// 🧹 Cleanup any duplicate issues with same hardwareId (master or slave) return reply.code(404).send({ message: "No matching issue found to move or update" });
}
// Cleanup duplicates
support.issues = support.issues.filter((i) => { support.issues = support.issues.filter((i) => {
const isMaster = i.hardwareId === hardwareId; const isMaster = i.hardwareId === hardwareId;
const isSlave = Array.isArray(i.hardwareIds) && i.hardwareIds.includes(hardwareId); const isSlave = Array.isArray(i.hardwareIds) && i.hardwareIds.includes(hardwareId);
@ -9201,9 +9213,6 @@ exports.moveIssueToCategory = async (req, reply) => {
await support.save(); await support.save();
return reply.send({ message: "Issue moved to category successfully" }); return reply.send({ message: "Issue moved to category successfully" });
} else {
return reply.code(404).send({ message: "No matching issue found to move" });
}
} catch (err) { } catch (err) {
console.error("Error moving issue:", err); console.error("Error moving issue:", err);
return reply.code(500).send({ error: "Internal Server Error" }); return reply.code(500).send({ error: "Internal Server Error" });
@ -9211,6 +9220,7 @@ exports.moveIssueToCategory = async (req, reply) => {
}; };
// exports.particularCategory = async (req, reply) => { // exports.particularCategory = async (req, reply) => {
// try { // try {
// const { supportId, category } = req.params; // const { supportId, category } = req.params;

Loading…
Cancel
Save