ashok 3 months ago
commit 512a81a61f

@ -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,30 +9466,29 @@ 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
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: {
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;

Loading…
Cancel
Save