comments time

master^2
Bhaskar 6 months ago
parent 98ed832f1f
commit a67f96c192

@ -5128,6 +5128,7 @@ exports.raiseATicketSlave = async (req, reply) => {
// } // }
// }; // };
exports.getDisconnectedIssuesBySupportId = async (req, reply) => { exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
try { try {
const { supportId, customerId } = req.params; 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)) { for (const master of Object.values(masterMap)) {
master.comments = commentTexts; master.comments = comments;
} }
return reply.send({ return reply.send({
@ -5325,6 +5332,7 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
}; };
// exports.getRemoveConnectedMastersWithSlaves = async (req, reply) => { // exports.getRemoveConnectedMastersWithSlaves = async (req, reply) => {
// try { // try {
// const { supportId } = req.params; // 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" }); 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 = { const commentObj = {
text: trimmedComment, text: trimmedComment,
customerId, customerId,
hardwareId, hardwareId,
createdAt: new Date() createdAt: moment().format("DD-MM-YYYY HH:mm")
}; };
if (!Array.isArray(supportRecord.comments)) { if (!Array.isArray(supportRecord.comments)) {
supportRecord.comments = []; supportRecord.comments = [];
} }
// Use push instead of spreading to keep Mongoose subdoc validation intact
supportRecord.comments.push(commentObj); supportRecord.comments.push(commentObj);
await supportRecord.save(); await supportRecord.save();
@ -7095,4 +7102,3 @@ exports.updateComments = async (req, reply) => {
return reply.code(500).send({ error: "Internal server error" }); return reply.code(500).send({ error: "Internal server error" });
} }
}; };

Loading…
Cancel
Save