comments added categorized issues side

master^2
Bhaskar 3 months ago
parent da910c341b
commit 189bc60c48

@ -9455,7 +9455,9 @@ exports.updateComments = async (req, reply) => {
}).lean(); }).lean();
if (!sensor) { 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 // Step 2: Load support record
@ -9464,29 +9466,28 @@ exports.updateComments = async (req, reply) => {
return reply.code(404).send({ error: "Support record not found" }); return reply.code(404).send({ error: "Support record not found" });
} }
// Step 3: Validate issue exists // Step 3: Check whether the hardwareId exists in issues or categorizedIssues
const issueExists = supportRecord.issues.some(issue => const issueExists =
issue.hardwareId === hardwareId || issue.masterHardwareId === hardwareId supportRecord.issues?.some(
); (issue) => issue.hardwareId === hardwareId || issue.masterHardwareId === hardwareId
) ||
supportRecord.categorizedIssues?.some(
(issue) => issue.hardwareId === hardwareId || issue.masterHardwareId === hardwareId
);
if (!issueExists) { 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 // Step 4: Append comment object
// const commentObj = {
// text: trimmedComment,
// customerId,
// hardwareId,
// createdAt: moment().format("DD-MM-YYYY HH:mm")
// };
const commentObj = { const commentObj = {
text: trimmedComment, text: trimmedComment,
customerId, customerId,
hardwareId, hardwareId,
createdAt: new Date() // ✅ correct Date object createdAt: new Date()
}; };
if (!Array.isArray(supportRecord.comments)) { if (!Array.isArray(supportRecord.comments)) {
supportRecord.comments = []; supportRecord.comments = [];
@ -9496,11 +9497,13 @@ exports.updateComments = async (req, reply) => {
await supportRecord.save(); await supportRecord.save();
return reply.send({ message: "Comment added successfully", comment: { return reply.send({
...commentObj, message: "Comment added successfully",
createdAt: moment(commentObj.createdAt).format("DD-MM-YYYY HH:mm") comment: {
}}); ...commentObj,
createdAt: moment(commentObj.createdAt).format("DD-MM-YYYY HH:mm")
}
});
} catch (error) { } catch (error) {
console.error("Error updating comments:", error); console.error("Error updating comments:", error);
return reply.code(500).send({ error: "Internal server error" }); return reply.code(500).send({ error: "Internal server error" });
@ -9508,6 +9511,7 @@ exports.updateComments = async (req, reply) => {
}; };
exports.resolvedIssuesForSupport = async (req, reply) => { exports.resolvedIssuesForSupport = async (req, reply) => {
try { try {
const { supportId } = req.params; const { supportId } = req.params;

Loading…
Cancel
Save