From 5c01fa5373806b968346d341abb44ab5bb89aad4 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 25 Jun 2025 11:09:46 +0530 Subject: [PATCH] changes --- src/controllers/installationController.js | 96 ++++++++++++++++++++++- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 1ed7acd6..5a860040 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -8296,6 +8296,99 @@ exports.deleteTeamMemberSupport = async (req, reply)=> { // } // }; +// exports.moveIssueToCategory = async (req, reply) => { +// try { +// const { supportId } = req.params; +// const { category, hardwareId } = req.body; + +// if (!supportId || !category || !hardwareId) { +// return reply.code(400).send({ +// message: "supportId (path), category and hardwareId (body) 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"); + +// if (!Array.isArray(support.categorizedIssues)) { +// support.categorizedIssues = []; +// } + +// const index = support.issues.findIndex((issue) => { +// if (issue.hardwareId === hardwareId) return true; +// 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" }); +// } + +// const issue = support.issues[index]; + +// // Normalize type if it's invalid +// const normalizedType = +// issue.type === "GSM or LoRa Disconnected" ? "GSM Disconnected" : issue.type; + +// if (issue.hardwareId === hardwareId) { +// issue.movedToCategory = true; + +// support.categorizedIssues.push({ +// type: normalizedType, +// hardwareId: issue.hardwareId, +// masterHardwareId: issue.masterHardwareId || issue.hardwareId, +// category, +// //ticketId : issue.ticketId, +// movedAt: nowTime, +// movedToCategory: true, +// }); + +// support.issues.splice(index, 1); +// issueMoved = true; +// } else { +// const slaveIndex = issue.hardwareIds.indexOf(hardwareId); +// if (slaveIndex !== -1) { +// const slaveName = issue.slaveNames?.[slaveIndex] || "Unknown"; + +// support.categorizedIssues.push({ +// type: normalizedType, +// hardwareId, +// masterHardwareId: issue.masterHardwareId || issue.hardwareId, +// slaveName, +// category, +// //ticketId : issue.ticketId, +// movedAt: nowTime, +// movedToCategory: true, +// }); + +// issue.hardwareIds.splice(slaveIndex, 1); +// issue.slaveNames.splice(slaveIndex, 1); + +// if (issue.hardwareIds.length === 0) { +// support.issues.splice(index, 1); +// } + +// issueMoved = true; +// } +// } + +// 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.moveIssueToCategory = async (req, reply) => { try { const { supportId } = req.params; @@ -8343,7 +8436,6 @@ exports.moveIssueToCategory = async (req, reply) => { hardwareId: issue.hardwareId, masterHardwareId: issue.masterHardwareId || issue.hardwareId, category, - //ticketId : issue.ticketId, movedAt: nowTime, movedToCategory: true, }); @@ -8361,7 +8453,6 @@ exports.moveIssueToCategory = async (req, reply) => { masterHardwareId: issue.masterHardwareId || issue.hardwareId, slaveName, category, - //ticketId : issue.ticketId, movedAt: nowTime, movedToCategory: true, }); @@ -8389,7 +8480,6 @@ exports.moveIssueToCategory = async (req, reply) => { } }; - // exports.particularCategory = async (req, reply) => { // try { // const { supportId, category } = req.params;