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) {
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 recent = prisma.wifiDevice.updateMany({
where: {
lastSeen: { gt: lastSeenThreshold },
status: 'ONLINE',
mac: { notIn: onlineDevicesMacs }
},
data: { status: 'RECENT' }
@ -54,7 +54,6 @@ async function updateDevicesStatus(onlineDevices) {
const offline = prisma.wifiDevice.updateMany({
where: {
lastSeen: { lte: lastSeenThreshold },
status: { not: 'OFFLINE' },
mac: { notIn: onlineDevicesMacs }
},
data: { status: 'OFFLINE' }

View File

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

View File

@ -18,6 +18,9 @@
<v-chip v-if="item.status == 'ONLINE'" color="green" dark x-small>
Online
</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>
</template>