ashok 3 months ago
commit 435e7ec3c6

@ -8806,64 +8806,58 @@ exports.updateHardwareList = async (req, reply) => {
const { hardwareList } = req.body; const { hardwareList } = req.body;
if (!supportId || !customerId || !hardwareId) { if (!supportId || !customerId || !hardwareId) {
return reply.code(400).send({ return reply.code(400).send({ error: "supportId, customerId, and hardwareId are required" });
error: "supportId, customerId, and hardwareId are required in path params",
});
} }
if (!hardwareList || typeof hardwareList !== "object") { if (!Array.isArray(hardwareList)) {
return reply.code(400).send({ return reply.code(400).send({ error: "hardwareList must be an array of objects" });
error: "hardwareList must be a valid object in request body",
});
} }
// ✅ Check if support record exists
const support = await Support.findOne({ supportId }).lean(); const support = await Support.findOne({ supportId }).lean();
if (!support) { if (!support) return reply.code(404).send({ error: "Support record not found" });
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 => const escalationIssue = (support.categorizedIssues || []).find(issue =>
issue.category === "Escalation" && issue.category === "Escalation" && issue.hardwareId === hardwareId
issue.hardwareId === hardwareId
); );
if (!escalationIssue) { if (!escalationIssue) {
return reply.code(403).send({ 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 }); const sensor = await Insensors.findOne({ customerId, hardwareId });
if (!sensor) { 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.hardwareList = hardwareList;
sensor.markModified('hardwareList');
await sensor.save(); await sensor.save();
return reply.send({ return reply.send({
status_code: 200, status_code: 200,
message: "Hardware list updated successfully for escalated issue", message: "Hardware list updated successfully",
data: { data: {
supportId, supportId,
customerId, customerId,
hardwareId, hardwareId,
hardwareList: sensor.hardwareList hardwareList: sensor.hardwareList // ← array format
} }
}); });
} catch (error) { } catch (err) {
console.error("Error updating hardware list:", error); console.error("Error updating hardwareList:", err);
return reply.code(500).send({ error: "Internal server error" }); return reply.code(500).send({ error: "Internal server error" });
} }
}; };
exports.assignCategorizeIssue = async (request, reply) => { exports.assignCategorizeIssue = async (request, reply) => {
const { supportId } = request.params; const { supportId } = request.params;
const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body; 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 }, lora_last_check_time : { type: String, default: null },
gsm_last_disconnect_time : { type: String, default: null }, gsm_last_disconnect_time : { type: String, default: null },
lora_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: [{ quality_check_details: [{
damage_check: { result: String }, damage_check: { result: String },
stickering_check: { result: String }, stickering_check: { result: String },
@ -641,11 +650,12 @@ outDoor_status: {
enum: ['inprogress', 'ready to pick up', 'dispatched'], enum: ['inprogress', 'ready to pick up', 'dispatched'],
default: 'inprogress' // optional: set default default: 'inprogress' // optional: set default
}, },
hardwareList: { // hardwareList: {
type: Map, // type: Map,
of: Number, // of: Number,
default: {} // default: {}
}, // },
distance_check: { distance_check: {
result: String, result: String,

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

Loading…
Cancel
Save