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