diff --git a/server/src/lib/wifiDevices.js b/server/src/lib/wifiDevices.js index ea574ba..19efcae 100644 --- a/server/src/lib/wifiDevices.js +++ b/server/src/lib/wifiDevices.js @@ -27,11 +27,12 @@ async function getOnlineDevices() { } async function updateDevicesStatus() { + const lastSeenThreshold = subMinutes(new Date(), RECENT_THRESHOLD_IN_MINUTES) + const recent = prisma.wifiDevice.updateMany({ where: { - status: 'OFFLINE', lastSeen: { - gt: subMinutes(new Date(), RECENT_THRESHOLD_IN_MINUTES) + gt: lastSeenThreshold } }, data: { @@ -42,7 +43,7 @@ async function updateDevicesStatus() { const offline = prisma.wifiDevice.updateMany({ where: { lastSeen: { - lte: subMinutes(new Date(), RECENT_THRESHOLD_IN_MINUTES) + lte: lastSeenThreshold } }, data: { @@ -111,10 +112,10 @@ async function updateDevicesInfo() { try { const onlineDevices = await getOnlineDevices() - await updateDB(onlineDevices) - await updateDevicesStatus() + await updateDB(onlineDevices) + pubsub.publish(USER_PRESENCE_UPDATED, { userPresenceUpdated: onlineDevices.length })