update comments for support

master^2
Bhaskar 6 months ago
parent 282c3bd4d8
commit da3dc19cd9

@ -6224,3 +6224,56 @@ exports.StatusTeamMember = async (request, reply) => {
}); });
} }
}; };
exports.updateComments = async (req, reply) => {
try {
const { supportId, customerId, hardwareId } = req.params;
const { comments } = req.body;
if (!supportId || !customerId || !hardwareId) {
return reply.code(400).send({ error: "supportId, customerId and hardwareId are required in path params" });
}
if (typeof comments !== 'string') {
return reply.code(400).send({ error: "comments must be a string in the request body" });
}
// Verify customerId is valid for the hardwareId by looking into Insensors
const sensor = await Insensors.findOne({
customerId,
$or: [{ hardwareId }, { tankhardwareId: hardwareId }]
}).lean();
if (!sensor) {
return reply.code(404).send({ error: "No sensor found with this hardwareId for this customerId" });
}
// Find support record only by supportId (no customerId in Support schema)
const supportRecord = await Support.findOne({ supportId });
if (!supportRecord) {
return reply.code(404).send({ error: "Support record not found" });
}
// Check if hardwareId exists in supportRecord issues
const issueExists = supportRecord.issues.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" });
}
// Update the comments field (top-level comments)
supportRecord.comments = comments;
await supportRecord.save();
return reply.send({ message: "Comments updated successfully", comments });
} catch (error) {
console.error("Error updating comments:", error);
return reply.code(500).send({ error: "Internal server error" });
}
};

@ -562,6 +562,30 @@ module.exports = function (fastify, opts, next) {
}, },
handler: installationController.getDisconnectedIssuesBySupportId, handler: installationController.getDisconnectedIssuesBySupportId,
}); });
fastify.put('/api/updateComments/:supportId/:customerId/:hardwareId', {
schema: {
description: "Update comments for a support record issue",
tags: ["Support"],
params: {
type: "object",
required: ["supportId", "customerId", "hardwareId"],
properties: {
supportId: { type: "string", minLength: 1 },
customerId: { type: "string", minLength: 1 },
hardwareId: { type: "string", minLength: 1 }
}
},
body: {
type: "object",
required: ["comments"],
properties: {
comments: { type: "string", minLength: 1 }
}
},
},
handler: installationController.updateComments
});
fastify.get("/api/getRemoveAllConnectedIsuues/:supportId/:hardwareId", { fastify.get("/api/getRemoveAllConnectedIsuues/:supportId/:hardwareId", {
schema: { schema: {
description: "Remove all connected list for Support", description: "Remove all connected list for Support",

Loading…
Cancel
Save