Save devices without user binding

This commit is contained in:
Douglas Barone 2021-01-11 15:47:22 -04:00
parent cc411fb88e
commit fe8a3e2217

View File

@ -95,6 +95,32 @@ async function updateDB(onlineDevices) {
}
})
} catch (e) {
// If is a binding problem, probably the device has an user outside of AD, so save it anyway...
if (e.code == 'P2016')
try {
await forceUserDisconnect(device.mac)
await prisma.wifiDevice.upsert({
where: { mac: device.mac },
create: {
...device,
hostname,
firstSeen: device.firstSeen || new Date(),
user: undefined
},
update: {
...device,
hostname,
user: undefined
}
})
} catch (e) {
logError({
tags: ['wifiDevices'],
message: `Error trying to upsert device with mac "${device.mac}". It has an user, but not in AD. And fails anyway...`,
data: { error: e, device }
})
}
else
logError({
tags: ['wifiDevices'],
message: `Error trying to upsert device with mac "${device.mac}"`,