diff --git a/server/src/resolvers/Query.js b/server/src/resolvers/Query.js index 8b4d834..52ba660 100755 --- a/server/src/resolvers/Query.js +++ b/server/src/resolvers/Query.js @@ -2,8 +2,6 @@ import { User } from '../classes/User' import prisma from '../prisma' -import { updateDevicesInfo } from '../utils/wifiUtils' - const parseSAMAccountName = sAMAccountName => sAMAccountName ? sAMAccountName.replace('.', ' ') : '' @@ -75,20 +73,7 @@ const Query = { }, async stats() { - return { - tokenCountTotal: prisma.resetToken.count(), - tokenCountUsed: prisma.resetToken.count({ - where: { NOT: { usedAt: null } } - }), - tokenCountExpired: prisma.resetToken.count({ - where: { - AND: [{ expiration: { lt: new Date() } }, { usedAt: null }] - } - }), - tokenCountNotUsed: prisma.resetToken.count({ - where: { usedAt: null, expiration: { gt: new Date() } } - }) - } + return {} }, async wifiDevices(_, { identifiedOnly, nonIdentifiedOnly }) { @@ -149,7 +134,7 @@ const Query = { a.wifiDevices[0].lastSeen > b.wifiDevices[0].lastSeen ? -1 : 1 ) - return sortedUserPresences.slice(0, 100) + return sortedUserPresences.slice(0, 1000) } } diff --git a/server/src/resolvers/Stats.js b/server/src/resolvers/Stats.js new file mode 100644 index 0000000..113e5c9 --- /dev/null +++ b/server/src/resolvers/Stats.js @@ -0,0 +1,41 @@ +import prisma from '../prisma' + +const Stats = { + tokenCountTotal: async () => prisma.resetToken.count(), + + tokenCountUsed: async () => + prisma.resetToken.count({ + where: { NOT: { usedAt: null } } + }), + + tokenCountExpired: async () => + prisma.resetToken.count({ + where: { + AND: [{ expiration: { lt: new Date() } }, { usedAt: null }] + } + }), + + tokenCountNotUsed: async () => + prisma.resetToken.count({ + where: { usedAt: null, expiration: { gt: new Date() } } + }), + + onlineUsers: async () => + prisma.user.count({ + where: { wifiDevices: { some: { status: 'ONLINE' } } } + }), + + offlineUsers: async () => + prisma.user.count({ + where: { + wifiDevices: { + every: { status: 'OFFLINE' }, + some: { lastSeen: { not: null } } + } + } + }), + + totalUsers: async () => prisma.user.count() +} + +export { Stats } diff --git a/server/src/resolvers/index.js b/server/src/resolvers/index.js index 6dea19a..051dff9 100755 --- a/server/src/resolvers/index.js +++ b/server/src/resolvers/index.js @@ -6,6 +6,7 @@ import { User } from './User' import { Group } from './Group' import { ResetToken } from './ResetToken' import { WifiDevice } from './WifiDevice' +import { Stats } from './Stats' const resolvers = { Query, @@ -14,7 +15,8 @@ const resolvers = { User, Group, ResetToken, - WifiDevice + WifiDevice, + Stats } export { resolvers } diff --git a/server/src/typeDefs.js b/server/src/typeDefs.js index 9a74583..0827388 100644 --- a/server/src/typeDefs.js +++ b/server/src/typeDefs.js @@ -144,6 +144,9 @@ const typeDefs = gql` tokenCountUsed: Int! tokenCountExpired: Int! tokenCountNotUsed: Int! + onlineUsers: Int! + offlineUsers: Int! + totalUsers: Int! } type WifiDevice { diff --git a/web/src/views/UserPresence.vue b/web/src/views/UserPresence.vue index 5820c62..c3592f3 100644 --- a/web/src/views/UserPresence.vue +++ b/web/src/views/UserPresence.vue @@ -13,6 +13,10 @@ /> +
+ {{ stats.onlineUsers }} usuários online. +
+