From 189bc60c489bf202a9b66c2c70e3bebc46c1b559 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 25 Jun 2025 12:39:01 +0530 Subject: [PATCH] comments added categorized issues side --- src/controllers/installationController.js | 52 ++++++++++++----------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 8dea0a3e..0e7abbd2 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -9455,7 +9455,9 @@ exports.updateComments = async (req, reply) => { }).lean(); if (!sensor) { - return reply.code(404).send({ error: "No sensor found with this hardwareId for this customerId" }); + return reply + .code(404) + .send({ error: "No sensor found with this hardwareId for this customerId" }); } // Step 2: Load support record @@ -9464,29 +9466,28 @@ exports.updateComments = async (req, reply) => { return reply.code(404).send({ error: "Support record not found" }); } - // Step 3: Validate issue exists - const issueExists = supportRecord.issues.some(issue => - issue.hardwareId === hardwareId || issue.masterHardwareId === hardwareId - ); + // Step 3: Check whether the hardwareId exists in issues or categorizedIssues + const issueExists = + supportRecord.issues?.some( + (issue) => issue.hardwareId === hardwareId || issue.masterHardwareId === hardwareId + ) || + supportRecord.categorizedIssues?.some( + (issue) => issue.hardwareId === hardwareId || issue.masterHardwareId === hardwareId + ); if (!issueExists) { - return reply.code(404).send({ error: "HardwareId not found in this support record's issues" }); + return reply + .code(404) + .send({ error: "HardwareId not found in issues or categorizedIssues for this support" }); } - // Step 4: Append comment object with formatted createdAt - // const commentObj = { - // text: trimmedComment, - // customerId, - // hardwareId, - // createdAt: moment().format("DD-MM-YYYY HH:mm") - // }; + // Step 4: Append comment object const commentObj = { - text: trimmedComment, - customerId, - hardwareId, - createdAt: new Date() // ✅ correct Date object -}; - + text: trimmedComment, + customerId, + hardwareId, + createdAt: new Date() + }; if (!Array.isArray(supportRecord.comments)) { supportRecord.comments = []; @@ -9496,11 +9497,13 @@ exports.updateComments = async (req, reply) => { await supportRecord.save(); - return reply.send({ message: "Comment added successfully", comment: { - ...commentObj, - createdAt: moment(commentObj.createdAt).format("DD-MM-YYYY HH:mm") - }}); - + return reply.send({ + message: "Comment added successfully", + comment: { + ...commentObj, + createdAt: moment(commentObj.createdAt).format("DD-MM-YYYY HH:mm") + } + }); } catch (error) { console.error("Error updating comments:", error); return reply.code(500).send({ error: "Internal server error" }); @@ -9508,6 +9511,7 @@ exports.updateComments = async (req, reply) => { }; + exports.resolvedIssuesForSupport = async (req, reply) => { try { const { supportId } = req.params;