From f7b3673dee58cebe61ad53c3b4cce25a9df5835d Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Thu, 25 Nov 2021 09:11:06 -0400 Subject: [PATCH] Return a promisse on updateDB() --- server/src/lib/wifiDevices.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/src/lib/wifiDevices.js b/server/src/lib/wifiDevices.js index d68ace8..151ccb2 100644 --- a/server/src/lib/wifiDevices.js +++ b/server/src/lib/wifiDevices.js @@ -84,7 +84,7 @@ function mockHostName({ mac, oui }) { } async function updateDB(onlineDevices) { - onlineDevices.map(device => { + const upsertPromises = onlineDevices.map(async device => { if (!device.user) forceUserDisconnect(device.mac) else device.user = device.user.replace('IFMS\\', '') @@ -94,7 +94,7 @@ async function updateDB(onlineDevices) { const hostname = device.hostname || mockHostName(device) - prisma.wifiDevice + return prisma.wifiDevice .upsert({ where: { mac: device.mac }, create: { @@ -138,11 +138,13 @@ async function updateDB(onlineDevices) { else logError({ tags: ['wifiDevices'], - message: `Erro tentando adicionar o dispositivo "${device.mac}".`, + message: `Erro tentando adicionar o dispositivo "${device.mac}: ${e.message}".`, data: { error: e, device } }) }) }) + + return Promise.allSettled(upsertPromises) } function updateDevicesInfo() {