From e6a62c13605afa6f084ef5591a5ba8fe0946fe51 Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Wed, 6 Apr 2022 08:04:52 -0400 Subject: [PATCH] Add filtering --- server/src/resolvers/Query/wifiDevices.js | 31 +++++++++++++++-------- server/src/typeDefs.js | 6 ++--- web/src/views/WifiDevices.vue | 19 ++++++++------ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/server/src/resolvers/Query/wifiDevices.js b/server/src/resolvers/Query/wifiDevices.js index e7b5e5a..f908c98 100644 --- a/server/src/resolvers/Query/wifiDevices.js +++ b/server/src/resolvers/Query/wifiDevices.js @@ -1,17 +1,28 @@ import prisma from '../../prisma' -// TODO: Add filtering -export async function wifiDevices(_, { identifiedOnly, nonIdentifiedOnly }) { - if (identifiedOnly && nonIdentifiedOnly) - throw new Error('Invalid combination of filters') +export async function wifiDevices(_, { take = 100, skip = 0, search }) { + const mode = 'insensitive' + + if (search === null) + search = undefined return prisma.wifiDevice.findMany({ + where: { + OR: [ + { hostname: { contains: search, mode } }, + { mac: { contains: search, mode } }, + { ip: { contains: search, mode } }, + { apName: { contains: search, mode } }, + { essid: { contains: search, mode } }, + { oui: { contains: search, mode } }, + { controller: { contains: search, mode } }, + { user: { displayName: { contains: search, mode } } }, + { user: { sAMAccountName: { contains: search, mode } } } + ] + }, orderBy: [{ lastSeen: 'desc' }, { hostname: 'asc' }], - where: identifiedOnly - ? { NOT: { userId: null } } - : nonIdentifiedOnly - ? { userId: null } - : {}, - include: { user: true } + include: { user: true }, + take, + skip }) } diff --git a/server/src/typeDefs.js b/server/src/typeDefs.js index f6523cc..e23d8ee 100644 --- a/server/src/typeDefs.js +++ b/server/src/typeDefs.js @@ -35,9 +35,9 @@ const typeDefs = gql` "Devices that uses the Wi-Fi" wifiDevices( - search: String = "" - identifiedOnly: Boolean = false - nonIdentifiedOnly: Boolean = false + search: String = "" + take: Int + skip: Int ): [WifiDevice]! @auth(roles: ["superAdmin"]) "Users that uses the Wi-Fi" diff --git a/web/src/views/WifiDevices.vue b/web/src/views/WifiDevices.vue index f4ae3bb..f9b430f 100644 --- a/web/src/views/WifiDevices.vue +++ b/web/src/views/WifiDevices.vue @@ -32,10 +32,7 @@
- {{ - wifiDevices && - wifiDevices.filter(device => device.status == 'ONLINE').length - }} + {{ stats.onlineWifiDevices }} online de @@ -48,7 +45,6 @@ :items-per-page.sync="itemsPerPage" :page="page" :loading="$apollo.queries.wifiDevices.loading" - :search="search" >