Extract method
This commit is contained in:
parent
a47f05ab18
commit
79d3bc47b9
|
@ -23,6 +23,7 @@ async function getOnlineDevices() {
|
||||||
return onlineDevices
|
return onlineDevices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add time threshold
|
||||||
async function setAllDevicesAsOffline() {
|
async function setAllDevicesAsOffline() {
|
||||||
await prisma.wifiDevice.updateMany({
|
await prisma.wifiDevice.updateMany({
|
||||||
data: {
|
data: {
|
||||||
|
@ -31,13 +32,16 @@ async function setAllDevicesAsOffline() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function forceUserDisconnect(mac) {
|
||||||
|
await prisma.$executeRaw(
|
||||||
|
'UPDATE "WifiDevice" SET "userId" = null WHERE mac = $1',
|
||||||
|
mac
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
async function updateDB(onlineDevices) {
|
async function updateDB(onlineDevices) {
|
||||||
for (const device of onlineDevices) {
|
for (const device of onlineDevices) {
|
||||||
if (!device.user)
|
if (!device.user) await forceUserDisconnect(device.mac)
|
||||||
await prisma.$executeRaw(
|
|
||||||
'UPDATE "WifiDevice" SET "userId" = null WHERE mac = $1',
|
|
||||||
device.mac
|
|
||||||
)
|
|
||||||
|
|
||||||
const user = device.user
|
const user = device.user
|
||||||
? { connect: { sAMAccountName: device.user } }
|
? { connect: { sAMAccountName: device.user } }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user