GET ALL disconnected list particular customer

master^2
Bhaskar 5 months ago
parent c3390d537c
commit f367785765

@ -4114,14 +4114,15 @@ exports.raiseATicketSlave = async (req, reply) => {
exports.getDisconnectedIssuesBySupportId = async (req, reply) => { exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
try { try {
const { supportId } = req.params; const { supportId, customerId } = req.params;
if (!supportId) {
return reply.code(400).send({ error: "supportId is required" }); if (!supportId || !customerId) {
return reply.code(400).send({ error: "supportId and customerId are required" });
} }
const supportRecord = await Support.findOne({ supportId }).lean(); const supportRecord = await Support.findOne({ supportId }).lean();
if (!supportRecord) { if (!supportRecord) {
return reply.code(404).send({ message: "No support record found for this supportId" }); return reply.code(404).send({ message: "No support record found for this supportId and customerId" });
} }
const allIssues = supportRecord.issues || []; const allIssues = supportRecord.issues || [];
@ -4135,6 +4136,7 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
const hardwareIds = [...hardwareSet]; const hardwareIds = [...hardwareSet];
const sensors = await Insensors.find({ const sensors = await Insensors.find({
customerId,
$or: [ $or: [
{ hardwareId: { $in: hardwareIds } }, { hardwareId: { $in: hardwareIds } },
{ tankhardwareId: { $in: hardwareIds } } { tankhardwareId: { $in: hardwareIds } }
@ -4147,16 +4149,6 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
if (sensor.tankhardwareId) sensorMap[sensor.tankhardwareId] = sensor; if (sensor.tankhardwareId) sensorMap[sensor.tankhardwareId] = sensor;
} }
let customerId = supportRecord.customerId;
if (!customerId) {
const firstSensor = sensors.find(sensor => sensor.customerId);
if (firstSensor) {
customerId = firstSensor.customerId;
} else {
return reply.code(404).send({ message: "Unable to determine customerId from support or sensors." });
}
}
const orders = await Order.find({ customerId }).lean(); const orders = await Order.find({ customerId }).lean();
const orderMap = {}; const orderMap = {};
@ -4216,7 +4208,8 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
const master = masterMap[masterSensor.hardwareId]; const master = masterMap[masterSensor.hardwareId];
const connectedSlaves = await Insensors.find({ const connectedSlaves = await Insensors.find({
connected_to: masterSensor.hardwareId, connected_to: masterSensor.hardwareId,
type: "slave" type: "slave",
customerId
}).lean(); }).lean();
const slaveSet = new Set(master.connected_slaves.map(s => s.hardwareId)); const slaveSet = new Set(master.connected_slaves.map(s => s.hardwareId));
@ -4260,8 +4253,9 @@ exports.getDisconnectedIssuesBySupportId = async (req, reply) => {
return reply.send({ return reply.send({
status_code: 200, status_code: 200,
supportId, supportId,
customerId,
totalMasters: Object.keys(masterMap).length, totalMasters: Object.keys(masterMap).length,
disconnectedIssues: Object.values(masterMap) // includes connected too disconnectedIssues: Object.values(masterMap)
}); });
} catch (error) { } catch (error) {

@ -546,7 +546,7 @@ module.exports = function (fastify, opts, next) {
}, },
handler: installationController.raiseATicketSlave, handler: installationController.raiseATicketSlave,
}); });
fastify.get("/api/getAllDisconnectedIsuues/:supportId", { fastify.get("/api/getAllDisconnectedIsuues/:supportId/:customerId", {
schema: { schema: {
description: "Get All disconnected list for Support", description: "Get All disconnected list for Support",
tags: ["Support"], tags: ["Support"],
@ -555,7 +555,7 @@ module.exports = function (fastify, opts, next) {
type: "object", type: "object",
properties: { properties: {
supportId: { type: "string" }, supportId: { type: "string" },
customerId: { type: "string" },
}, },
required: [ "supportId"], required: [ "supportId"],
}, },

Loading…
Cancel
Save