Sort result

This commit is contained in:
Douglas Barone 2020-12-16 11:18:45 -04:00
parent 53cfbbf7e1
commit acbe13a0b1

View File

@ -92,10 +92,18 @@ const Query = {
}, },
async wifiUsers() { async wifiUsers() {
return prisma.user.findMany({ const wifiUsers = await prisma.user.findMany({
where: { wifiDevices: { some: { id: { not: undefined } } } }, where: { wifiDevices: { some: { id: { not: undefined } } } },
include: { wifiDevices: true } include: { wifiDevices: true }
}) })
wifiUsers.sort(
(a, b) =>
b.wifiDevices.filter(device => device.isOnline).length -
a.wifiDevices.filter(device => device.isOnline).length
)
return wifiUsers
}, },
async userPresence(_, { search }) { async userPresence(_, { search }) {