master^2
Bhaskar 6 months ago
parent 7d52f1ab91
commit 24295e24a8

@ -1018,21 +1018,22 @@ exports.getMasterSlaveSummary = async (req, reply) => {
// Update connection status and timestamps
const updateStatusPromises = allDevices.map(async device => {
let checkHardwareId = device.hardwareId?.trim();
if (!checkHardwareId) return;
let checkHardwareId;
// For slave, check connection via master's hardwareId (i.e., connected_to)
if (device.type === 'slave') {
checkHardwareId = device.connected_to?.trim();
if (!checkHardwareId) return;
if (device.type === 'master') {
checkHardwareId = device.hardwareId?.trim();
} else if (device.type === 'slave') {
checkHardwareId = device.hardwareId?.trim(); // Use slave's own hardwareId
}
if (!checkHardwareId) return;
const latestData = await IotData.findOne({ hardwareId: checkHardwareId })
.sort({ date: -1 })
.lean();
let status = "disconnected";
let updateFields = {};
const updateFields = {};
if (latestData?.date) {
const now = moment();
@ -1067,6 +1068,8 @@ exports.getMasterSlaveSummary = async (req, reply) => {
device.connected_status = status;
});
await Promise.all(updateStatusPromises);
// Build enriched masters and exclude irrelevant fields

Loading…
Cancel
Save