ashok 3 months ago
commit 435e7ec3c6

@ -8806,64 +8806,58 @@ exports.updateHardwareList = async (req, reply) => {
const { hardwareList } = req.body;
if (!supportId || !customerId || !hardwareId) {
return reply.code(400).send({
error: "supportId, customerId, and hardwareId are required in path params",
});
return reply.code(400).send({ error: "supportId, customerId, and hardwareId are required" });
}
if (!hardwareList || typeof hardwareList !== "object") {
return reply.code(400).send({
error: "hardwareList must be a valid object in request body",
});
if (!Array.isArray(hardwareList)) {
return reply.code(400).send({ error: "hardwareList must be an array of objects" });
}
// ✅ Check if support record exists
const support = await Support.findOne({ supportId }).lean();
if (!support) {
return reply.code(404).send({ error: "Support record not found" });
}
if (!support) return reply.code(404).send({ error: "Support record not found" });
// ✅ Ensure at least one escalation issue exists for that hardware and customer
const escalationIssue = (support.categorizedIssues || []).find(issue =>
issue.category === "Escalation" &&
issue.hardwareId === hardwareId
issue.category === "Escalation" && issue.hardwareId === hardwareId
);
if (!escalationIssue) {
return reply.code(403).send({
error: "Update not allowed. Escalation issue not found for this supportId and hardwareId.",
error: "Escalation issue not found. Cannot update hardware list."
});
}
// ✅ Check if the Insensors document exists
const sensor = await Insensors.findOne({ customerId, hardwareId });
if (!sensor) {
return reply.code(404).send({ message: "Insensor not found for the given customerId and hardwareId" });
return reply.code(404).send({ error: "Insensor not found" });
}
// ✅ Update hardwareList
sensor.hardwareList = hardwareList;
sensor.markModified('hardwareList');
await sensor.save();
return reply.send({
status_code: 200,
message: "Hardware list updated successfully for escalated issue",
message: "Hardware list updated successfully",
data: {
supportId,
customerId,
hardwareId,
hardwareList: sensor.hardwareList
hardwareList: sensor.hardwareList // ← array format
}
});
} catch (error) {
console.error("Error updating hardware list:", error);
} catch (err) {
console.error("Error updating hardwareList:", err);
return reply.code(500).send({ error: "Internal server error" });
}
};
exports.assignCategorizeIssue = async (request, reply) => {
const { supportId } = request.params;
const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body;

@ -616,6 +616,15 @@ team_member_support_lora_last_check_time : { type: String, default: null },
lora_last_check_time : { type: String, default: null },
gsm_last_disconnect_time : { type: String, default: null },
lora_last_disconnect_time : { type: String, default: null },
hardwareList: {
type: [
{
name: { type: String, required: true },
value: { type: Number, required: true }
}
],
default: []
},
quality_check_details: [{
damage_check: { result: String },
stickering_check: { result: String },
@ -641,11 +650,12 @@ outDoor_status: {
enum: ['inprogress', 'ready to pick up', 'dispatched'],
default: 'inprogress' // optional: set default
},
hardwareList: {
type: Map,
of: Number,
default: {}
},
// hardwareList: {
// type: Map,
// of: Number,
// default: {}
// },
distance_check: {
result: String,

@ -888,11 +888,11 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: 'POST',
url: '/api/updateHarwareList/:supportId/:customerId/:hardwareId',
url: '/api/updateHardwareList/:supportId/:customerId/:hardwareId',
schema: {
tags: ['Support'],
summary: 'Update hardware list for an escalated issue',
description: 'Updates the hardwareList in Insensors schema only if issue is categorized as Escalation',
description: 'Updates the hardwareList (array of name-value objects) in Insensors schema only if issue is categorized as Escalation',
params: {
type: 'object',
required: ['supportId', 'customerId', 'hardwareId'],
@ -907,16 +907,23 @@ fastify.route({
required: ['hardwareList'],
properties: {
hardwareList: {
type: 'array',
description: 'List of hardware components as name-value objects',
items: {
type: 'object',
description: 'Hardware summary object (e.g. { masters: 2, slaves: 2 })',
additionalProperties: { type: 'number' },
example: {
masters: 2,
slaves: 2,
sensors: 4,
plugs: 3,
wires: 200
required: ['name', 'value'],
properties: {
name: { type: 'string', description: 'Component name (e.g., masters, slaves)' },
value: { type: 'number', description: 'Quantity of the component' }
}
},
example: [
{ name: 'masters', value: 2 },
{ name: 'slaves', value: 2 },
{ name: 'sensors', value: 4 },
{ name: 'plugs', value: 3 },
{ name: 'wires', value: 200 }
]
}
}
},
@ -934,8 +941,14 @@ fastify.route({
customerId: { type: 'string' },
hardwareId: { type: 'string' },
hardwareList: {
type: 'array',
items: {
type: 'object',
additionalProperties: { type: 'number' }
properties: {
name: { type: 'string' },
value: { type: 'number' }
}
}
}
}
}
@ -974,6 +987,7 @@ fastify.route({
handler: installationController.updateHardwareList
});
fastify.post("/api/my-categorized-issues/:support_teamMemberId/:customerId", {
schema: {
description: "Get categorized issues by team member and customer",

Loading…
Cancel
Save