Improved online detection

This commit is contained in:
Douglas Barone 2023-12-14 13:09:23 -04:00
parent 9964c5fac6
commit f276202696
3 changed files with 9 additions and 5 deletions

View File

@ -38,14 +38,14 @@ async function getOnlineDevices() {
} }
async function updateDevicesStatus(onlineDevices) { async function updateDevicesStatus(onlineDevices) {
const lastSeenThreshold = subMinutes(new Date(), RECENT_THRESHOLD_IN_MINUTES) const now = new Date()
const lastSeenThreshold = subMinutes(now, RECENT_THRESHOLD_IN_MINUTES)
const onlineDevicesMacs = onlineDevices.map(device => device.mac) const onlineDevicesMacs = onlineDevices.map(device => device.mac)
const recent = prisma.wifiDevice.updateMany({ const recent = prisma.wifiDevice.updateMany({
where: { where: {
lastSeen: { gt: lastSeenThreshold }, lastSeen: { gt: lastSeenThreshold },
status: 'ONLINE',
mac: { notIn: onlineDevicesMacs } mac: { notIn: onlineDevicesMacs }
}, },
data: { status: 'RECENT' } data: { status: 'RECENT' }
@ -54,7 +54,6 @@ async function updateDevicesStatus(onlineDevices) {
const offline = prisma.wifiDevice.updateMany({ const offline = prisma.wifiDevice.updateMany({
where: { where: {
lastSeen: { lte: lastSeenThreshold }, lastSeen: { lte: lastSeenThreshold },
status: { not: 'OFFLINE' },
mac: { notIn: onlineDevicesMacs } mac: { notIn: onlineDevicesMacs }
}, },
data: { status: 'OFFLINE' } data: { status: 'OFFLINE' }

View File

@ -47,19 +47,21 @@ const User = {
isWatcher: parent => parent.roles.includes('watcher'), isWatcher: parent => parent.roles.includes('watcher'),
wifiDevices: (parent, data, { auth }) => { wifiDevices: async (parent, data, { auth }) => {
if ( if (
parent.sAMAccountName !== auth.sAMAccountName && parent.sAMAccountName !== auth.sAMAccountName &&
!auth.roles.includes('superAdmin') !auth.roles.includes('superAdmin')
) )
return [] return []
return prisma.wifiDevice.findMany({ const wifiDevices = await prisma.wifiDevice.findMany({
where: { where: {
accessPointId: { not: null }, accessPointId: { not: null },
user: { id: parent.id } user: { id: parent.id }
} }
}) })
return wifiDevices
}, },
campus: parent => { campus: parent => {

View File

@ -18,6 +18,9 @@
<v-chip v-if="item.status == 'ONLINE'" color="green" dark x-small> <v-chip v-if="item.status == 'ONLINE'" color="green" dark x-small>
Online Online
</v-chip> </v-chip>
<v-chip v-else-if="item.status == 'RECENT'" color="orange" dark x-small>
Recente
</v-chip>
<v-chip v-else color="grey" dark x-small>Offline</v-chip> <v-chip v-else color="grey" dark x-small>Offline</v-chip>
</template> </template>