master^2
Bhaskar 5 months ago
parent 573dcd299e
commit b102b7d61f

@ -3914,12 +3914,12 @@ exports.deleteTeamMemberSupport = async (req, reply)=> {
exports.moveIssueToCategory = async (req, reply) => { exports.moveIssueToCategory = async (req, reply) => {
try { try {
const { supportId, category } = req.body; const { supportId } = req.params;
const { hardwareId, tankhardwareId } = req.body; const { category, hardwareId } = req.body;
if (!supportId || !category || (!hardwareId && !tankhardwareId)) { if (!supportId || !category || !hardwareId) {
return reply.code(400).send({ return reply.code(400).send({
message: "supportId, category, and hardwareId or tankhardwareId are required", message: "supportId (path), category and hardwareId (body) are required",
}); });
} }
@ -3931,62 +3931,59 @@ 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 array exists
if (!Array.isArray(support.categorizedIssues)) { if (!Array.isArray(support.categorizedIssues)) {
support.categorizedIssues = []; support.categorizedIssues = [];
} }
// Master Issue Move // Find the issue where hardwareId matches either hardwareId or inside hardwareIds array
if (hardwareId && !tankhardwareId) { const index = support.issues.findIndex((issue) => {
const index = support.issues.findIndex( // Master hardwareId match
(issue) => issue.hardwareId === hardwareId && issue.masterHardwareId === hardwareId if (issue.hardwareId === hardwareId) return true;
); // Slave hardwareIds array match
if (Array.isArray(issue.hardwareIds) && issue.hardwareIds.includes(hardwareId)) return true;
return false;
});
if (index === -1) {
return reply.code(404).send({ message: "No matching issue found to move" });
}
if (index !== -1) { const issue = support.issues[index];
const issue = support.issues[index];
// If the hardwareId matches master hardwareId, move entire issue as is
if (issue.hardwareId === hardwareId) {
support.categorizedIssues.push({
...issue,
category,
movedAt: nowTime,
});
support.issues.splice(index, 1);
issueMoved = true;
} else {
// hardwareId matches inside hardwareIds array — move that slave issue individually
const slaveIndex = issue.hardwareIds.indexOf(hardwareId);
if (slaveIndex !== -1) {
const slaveName = issue.slaveNames?.[slaveIndex] || "Unknown";
support.categorizedIssues.push({ support.categorizedIssues.push({
...issue, type: issue.type,
hardwareId,
masterHardwareId: issue.masterHardwareId || issue.hardwareId,
slaveName,
category, category,
movedAt: nowTime, movedAt: nowTime,
}); });
support.issues.splice(index, 1); // Remove slave from issue
issueMoved = true; issue.hardwareIds.splice(slaveIndex, 1);
} issue.slaveNames.splice(slaveIndex, 1);
}
// 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 // If no more slaves left, remove the issue completely
issue.hardwareIds.splice(slaveIndex, 1); if (issue.hardwareIds.length === 0) {
issue.slaveNames.splice(slaveIndex, 1); support.issues.splice(index, 1);
// Remove issue completely if no more slaves
if (issue.hardwareIds.length === 0) {
support.issues.splice(i, 1);
}
issueMoved = true;
break;
} }
issueMoved = true;
} }
} }

@ -641,24 +641,26 @@ module.exports = function (fastify, opts, next) {
}); });
fastify.post("/api/moveIssueToCategory", { fastify.post("/api/moveIssueToCategory/:supportId", {
schema: { schema: {
description: "Move specific issue to a categorized bucket", description: "Move specific issue to a categorized bucket",
tags: ["Support"], tags: ["Support"],
summary: "Move disconnected issue to category and remove from issues list", summary: "Move disconnected issue to category and remove from issues list",
body: { params: {
type: "object", type: "object",
required: ["supportId", "category"], required: ["supportId"],
properties: { properties: {
supportId: { type: "string" }, supportId: { type: "string" },
category: { },
type: "string", },
enum: ["Power Outage", "Level1", "Pending", "Onsite Issues"] body: {
}, type: "object",
hardwareId: { type: "string" }, // master required: ["category", "hardwareId"],
tankhardwareId: { type: "string" } // slave properties: {
} category: { type: "string" },
} hardwareId: { type: "string" },
},
},
}, },
handler: installationController.moveIssueToCategory handler: installationController.moveIssueToCategory
}); });

Loading…
Cancel
Save