ashok 3 months ago
commit 94d39bfe28

@ -8799,6 +8799,70 @@ exports.particularCategory = async (req, reply) => {
}
};
exports.updateHardwareList = async (req, reply) => {
try {
const { supportId, customerId, hardwareId } = req.params;
const { hardwareList } = req.body;
if (!supportId || !customerId || !hardwareId) {
return reply.code(400).send({
error: "supportId, customerId, and hardwareId are required in path params",
});
}
if (!hardwareList || typeof hardwareList !== "object") {
return reply.code(400).send({
error: "hardwareList must be a valid object in request body",
});
}
// ✅ Check if support record exists
const support = await Support.findOne({ supportId }).lean();
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
);
if (!escalationIssue) {
return reply.code(403).send({
error: "Update not allowed. Escalation issue not found for this supportId and hardwareId.",
});
}
// ✅ 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" });
}
// ✅ Update hardwareList
sensor.hardwareList = hardwareList;
await sensor.save();
return reply.send({
status_code: 200,
message: "Hardware list updated successfully for escalated issue",
data: {
supportId,
customerId,
hardwareId,
hardwareList: sensor.hardwareList
}
});
} catch (error) {
console.error("Error updating hardware list:", error);
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;

@ -641,6 +641,12 @@ outDoor_status: {
enum: ['inprogress', 'ready to pick up', 'dispatched'],
default: 'inprogress' // optional: set default
},
hardwareList: {
type: Map,
of: Number,
default: {}
},
distance_check: {
result: String,
steps: [

@ -886,6 +886,93 @@ module.exports = function (fastify, opts, next) {
handler: installationController.assignCategorizeIssue
});
fastify.route({
method: 'POST',
url: '/api/updateHarwareList/: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',
params: {
type: 'object',
required: ['supportId', 'customerId', 'hardwareId'],
properties: {
supportId: { type: 'string', description: 'Support record ID' },
customerId: { type: 'string', description: 'Customer ID' },
hardwareId: { type: 'string', description: 'Hardware ID of the master/slave' }
}
},
body: {
type: 'object',
required: ['hardwareList'],
properties: {
hardwareList: {
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
}
}
}
},
response: {
200: {
description: 'Successfully updated hardwareList',
type: 'object',
properties: {
status_code: { type: 'number' },
message: { type: 'string' },
data: {
type: 'object',
properties: {
supportId: { type: 'string' },
customerId: { type: 'string' },
hardwareId: { type: 'string' },
hardwareList: {
type: 'object',
additionalProperties: { type: 'number' }
}
}
}
}
},
400: {
description: 'Missing or invalid input',
type: 'object',
properties: {
error: { type: 'string' }
}
},
403: {
description: 'Not allowed (issue is not escalated)',
type: 'object',
properties: {
error: { type: 'string' }
}
},
404: {
description: 'Support or sensor not found',
type: 'object',
properties: {
error: { type: 'string' }
}
},
500: {
description: 'Internal server error',
type: 'object',
properties: {
error: { type: 'string' }
}
}
}
},
handler: installationController.updateHardwareList
});
fastify.post("/api/my-categorized-issues/:support_teamMemberId/:customerId", {
schema: {

Loading…
Cancel
Save