From 4429c84b1c651bc21d7c99f616d82459c0aabaa2 Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Tue, 7 Jun 2022 16:34:52 +0000 Subject: [PATCH] Add pagination to WifiUsers --- server/src/resolvers/Query/wifiUsers.js | 77 ++++++++------- server/src/typeDefs.js | 20 ++-- .../DataTables/UserWifiDevicesDataTable.vue | 6 +- .../DataTables/WifiDevicesDataTable.vue | 6 +- web/src/views/WifiUsers.vue | 99 ++++++++++++------- 5 files changed, 129 insertions(+), 79 deletions(-) diff --git a/server/src/resolvers/Query/wifiUsers.js b/server/src/resolvers/Query/wifiUsers.js index 56db13a..5d95cae 100644 --- a/server/src/resolvers/Query/wifiUsers.js +++ b/server/src/resolvers/Query/wifiUsers.js @@ -1,46 +1,53 @@ import prisma from '../../prisma' // TODO: Add filtering -export async function wifiUsers(parent, { take = 100, skip = 0, search }) { +export async function wifiUsers(parent, { take = 10, skip = 0, search }) { const mode = 'insensitive' if (search === null) search = undefined - return prisma.user.findMany({ - where: { - AND: [ - { wifiDevices: { some: { id: { not: undefined } } } }, - { - OR: [ - { wifiDevices: { some: { hostname: { contains: search, mode } } } }, - { - wifiDevices: { - some: { - accessPoint: { - OR: [ - { name: { contains: search, mode } }, - { local: { contains: search, mode } }, - ] - } + const where = { + AND: [ + { wifiDevices: { some: { id: { not: undefined } } } }, + { + OR: [ + { wifiDevices: { some: { hostname: { contains: search, mode } } } }, + { + wifiDevices: { + some: { + accessPoint: { + OR: [ + { name: { contains: search, mode } }, + { local: { contains: search, mode } }, + ] } } - }, - { wifiDevices: { some: { mac: { contains: search, mode } } } }, - { wifiDevices: { some: { ip: { contains: search, mode } } } }, - { displayName: { contains: search, mode } }, , - { sAMAccountName: { contains: search, mode } }, - ] - } - ] - }, - include: { - wifiDevices: true - }, - orderBy: [ - { wifiDevices: { _count: 'desc' } }, - { displayName: 'asc' }], - take, - skip - }) + } + }, + { wifiDevices: { some: { mac: { contains: search, mode } } } }, + { wifiDevices: { some: { ip: { contains: search, mode } } } }, + { displayName: { contains: search, mode } }, , + { sAMAccountName: { contains: search, mode } }, + ] + } + ] + } + + return { + data: + prisma.user.findMany({ + where, + include: { + wifiDevices: true + }, + orderBy: [ + { wifiDevices: { _count: 'desc' } }, + { displayName: 'asc' }], + take, + skip + }), + + total: prisma.user.count({ where }) + } } diff --git a/server/src/typeDefs.js b/server/src/typeDefs.js index 6b10773..468de52 100644 --- a/server/src/typeDefs.js +++ b/server/src/typeDefs.js @@ -42,7 +42,7 @@ const typeDefs = gql` wifiUsers( search: String = "" take: Int - skip: Int): [User]! @auth(roles: ["superAdmin"]) + skip: Int): WifiUsersResult! @auth(roles: ["superAdmin"]) "Application Logs" logs( @@ -243,12 +243,6 @@ const typeDefs = gql` usage: Int } - "A WiFi Device Search result" - type WifiDevicesResult { - data: [WifiDevice!]! - total: Int! - } - "A user that is on the Wi-Fi network reach" type UserPresence { id: ID! @@ -327,6 +321,18 @@ const typeDefs = gql` wifiDevices: [WifiDevice] } + "A WiFi Device Search result" + type WifiDevicesResult { + data: [WifiDevice!]! + total: Int! + } + + "A WiFi User Search result" + type WifiUsersResult { + data: [User!]! + total: Int! + } + "Subnet information" type SubnetInfo { shortName: String! diff --git a/web/src/components/DataTables/UserWifiDevicesDataTable.vue b/web/src/components/DataTables/UserWifiDevicesDataTable.vue index a5af963..56abcbc 100644 --- a/web/src/components/DataTables/UserWifiDevicesDataTable.vue +++ b/web/src/components/DataTables/UserWifiDevicesDataTable.vue @@ -108,4 +108,8 @@ export default { } - + diff --git a/web/src/components/DataTables/WifiDevicesDataTable.vue b/web/src/components/DataTables/WifiDevicesDataTable.vue index 3fcf561..3e79420 100644 --- a/web/src/components/DataTables/WifiDevicesDataTable.vue +++ b/web/src/components/DataTables/WifiDevicesDataTable.vue @@ -130,4 +130,8 @@ export default { } - + diff --git a/web/src/views/WifiUsers.vue b/web/src/views/WifiUsers.vue index 6a1f3c4..b50e911 100644 --- a/web/src/views/WifiUsers.vue +++ b/web/src/views/WifiUsers.vue @@ -1,14 +1,25 @@