remove from the list

master^2
Bhaskar 3 months ago
parent 6c5a6e67c2
commit a8740aa792

@ -8468,11 +8468,12 @@ exports.moveIssueToCategory = async (req, reply) => {
const issue = support.issues[index];
// Normalize type if it's invalid
// Normalize type if needed
const normalizedType =
issue.type === "GSM or LoRa Disconnected" ? "GSM Disconnected" : issue.type;
if (issue.hardwareId === hardwareId) {
// Master issue
issue.movedToCategory = true;
support.categorizedIssues.push({
@ -8487,6 +8488,7 @@ exports.moveIssueToCategory = async (req, reply) => {
support.issues.splice(index, 1);
issueMoved = true;
} else {
// Slave issue
const slaveIndex = issue.hardwareIds.indexOf(hardwareId);
if (slaveIndex !== -1) {
const slaveName = issue.slaveNames?.[slaveIndex] || "Unknown";
@ -8504,6 +8506,7 @@ exports.moveIssueToCategory = async (req, reply) => {
issue.hardwareIds.splice(slaveIndex, 1);
issue.slaveNames.splice(slaveIndex, 1);
// Remove full issue if no more slaves are left
if (issue.hardwareIds.length === 0) {
support.issues.splice(index, 1);
}
@ -8513,6 +8516,15 @@ exports.moveIssueToCategory = async (req, reply) => {
}
if (issueMoved) {
await support.save();
// 🧹 Cleanup any duplicate issues with same hardwareId (master or slave)
support.issues = support.issues.filter((i) => {
const isMaster = i.hardwareId === hardwareId;
const isSlave = Array.isArray(i.hardwareIds) && i.hardwareIds.includes(hardwareId);
return !isMaster && !isSlave;
});
await support.save();
return reply.send({ message: "Issue moved to category successfully" });
} else {
@ -8524,6 +8536,7 @@ exports.moveIssueToCategory = async (req, reply) => {
}
};
// exports.particularCategory = async (req, reply) => {
// try {
// const { supportId, category } = req.params;

Loading…
Cancel
Save