Extract method

This commit is contained in:
Douglas Barone 2020-12-17 13:15:22 -04:00
parent a47f05ab18
commit 79d3bc47b9

View File

@ -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 } }