From a67f96c1920794d51ef9f7e7b4f8a91eb04e0e4e Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 4 Jun 2025 11:35:36 +0530 Subject: [PATCH] comments time --- src/controllers/installationController.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 355bb976..c73a327d 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -5128,6 +5128,7 @@ exports.raiseATicketSlave = async (req, reply) => { // } // }; + exports.getDisconnectedIssuesBySupportId = async (req, reply) => { try { const { supportId, customerId } = req.params; @@ -5305,9 +5306,15 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => { } } - const commentTexts = (supportRecord.comments || []).map(c => c.text); + // Add comments with text and createdAt to each master device + const comments = (supportRecord.comments || []).map(c => ({ + text: c.text, + commentsTime: moment(c.createdAt).tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm") + })); + + for (const master of Object.values(masterMap)) { - master.comments = commentTexts; + master.comments = comments; } return reply.send({ @@ -5325,6 +5332,7 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => { }; + // exports.getRemoveConnectedMastersWithSlaves = async (req, reply) => { // try { // const { supportId } = req.params; @@ -7071,19 +7079,18 @@ exports.updateComments = async (req, reply) => { return reply.code(404).send({ error: "HardwareId not found in this support record's issues" }); } - // Step 4: Append comment object correctly + // Step 4: Append comment object with formatted createdAt const commentObj = { text: trimmedComment, customerId, hardwareId, - createdAt: new Date() + createdAt: moment().format("DD-MM-YYYY HH:mm") }; if (!Array.isArray(supportRecord.comments)) { supportRecord.comments = []; } - // Use push instead of spreading to keep Mongoose subdoc validation intact supportRecord.comments.push(commentObj); await supportRecord.save(); @@ -7095,4 +7102,3 @@ exports.updateComments = async (req, reply) => { return reply.code(500).send({ error: "Internal server error" }); } }; -