ashok 4 months ago
commit 128e8ec7e7

@ -3929,7 +3929,7 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => {
const sensorCurrent = sensors.find(
(s) => s.tankhardwareId?.trim().toLowerCase() === slave.slaveHardwareId
);
console.log("sensorCurrent",sensorCurrent)
if (
sensorCurrent &&
sensorCurrent.connected_status === "disconnected" &&
@ -5954,6 +5954,9 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
}
}
// Debug: Log issue hardware IDs being considered
console.log("✅ All issue hardwareIds:", Array.from(allHardwareIds));
// Step 4: If no valid hardware IDs left, stop
if (allHardwareIds.size === 0) {
return reply.code(404).send({ message: "No unresolved hardware IDs found in issues" });
@ -5971,6 +5974,9 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
]
}).lean();
// Debug: Log disconnected sensors found
console.log("⚙️ Disconnected sensors matched:", disconnectedSensors.map(s => s.hardwareId));
if (!disconnectedSensors.length) {
return reply.code(404).send({ message: "No disconnected issues found" });
}
@ -5990,6 +5996,23 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
const sensorHw = sensor.tankhardwareId?.trim().toLowerCase();
const sensorConnected = sensor.connected_to?.trim().toLowerCase();
// for (const issue of unresolvedIssues) {
// const allIssueHardwareIds = [
// ...(issue.hardwareIds?.map(id => id?.trim().toLowerCase()) || []),
// issue.hardwareId?.trim().toLowerCase()
// ];
// if (
// (sensorHw && allIssueHardwareIds.includes(sensorHw)) ||
// (sensorConnected && allIssueHardwareIds.includes(sensorConnected))
// ) {
// if (issue.hardwareId && !existingCategorizedHardwareIds.has(issue.hardwareId.trim().toLowerCase())) {
// customerHardwareMap[custId].add(issue.hardwareId.trim().toLowerCase());
// }
// }
// }
const sensorHardwareId = sensor.hardwareId?.trim().toLowerCase();
for (const issue of unresolvedIssues) {
const allIssueHardwareIds = [
...(issue.hardwareIds?.map(id => id?.trim().toLowerCase()) || []),
@ -5998,15 +6021,25 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
if (
(sensorHw && allIssueHardwareIds.includes(sensorHw)) ||
(sensorConnected && allIssueHardwareIds.includes(sensorConnected))
(sensorConnected && allIssueHardwareIds.includes(sensorConnected)) ||
(sensorHardwareId && allIssueHardwareIds.includes(sensorHardwareId))
) {
if (issue.hardwareId && !existingCategorizedHardwareIds.has(issue.hardwareId.trim().toLowerCase())) {
customerHardwareMap[custId].add(issue.hardwareId.trim().toLowerCase());
for (const hw of allIssueHardwareIds) {
if (hw && !existingCategorizedHardwareIds.has(hw)) {
customerHardwareMap[custId].add(hw);
}
}
}
}
}
// Debug: Log map of matched customer hardware
console.log("📌 Customer hardware map:", Object.fromEntries(
Object.entries(customerHardwareMap).map(([k, v]) => [k, Array.from(v)])
));
// Step 8: Build final response
const response = [];
for (const user of customers) {
@ -6078,7 +6111,7 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
});
} catch (error) {
console.error("Error fetching disconnected customer details:", error);
console.error("Error fetching disconnected customer details:", error);
return reply.code(500).send({ error: "Internal server error" });
}
};

Loading…
Cancel
Save