|
|
|
@ -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" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|