diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index b84e70b3..2c318b9f 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -4570,19 +4570,24 @@ exports.getDisconnectedCustomerDetailsByTeamMemberId = async (req, reply) => { } // 2. Extract all hardwareIds from issues - const hardwareIds = []; - for (const issue of supportRecord.issues || []) { - if (issue.hardwareId) hardwareIds.push(issue.hardwareId); - if (Array.isArray(issue.hardwareIds)) hardwareIds.push(...issue.hardwareIds); - } + // 2. Extract all hardwareIds and masterHardwareIds from issues +const hardwareIds = []; +for (const issue of supportRecord.issues || []) { + if (issue.hardwareId) hardwareIds.push(issue.hardwareId); + if (Array.isArray(issue.hardwareIds)) hardwareIds.push(...issue.hardwareIds); + if (issue.masterHardwareId) hardwareIds.push(issue.masterHardwareId); // Add this line +} + if (hardwareIds.length === 0) { return reply.code(404).send({ message: "No hardware IDs found in issues" }); } - + console.log("hardwareIds",hardwareIds) // 3. Find disconnected Insensors matching connected_to + const uniqueHardwareIds = [...new Set(hardwareIds)]; + const disconnectedSensors = await Insensors.find({ - connected_to: { $in: hardwareIds }, + connected_to: { $in: uniqueHardwareIds }, connected_status: "disconnected" }).lean();