Added onlineUsers to Stats
This commit is contained in:
parent
7f763020c7
commit
2e454ea88f
|
@ -2,8 +2,6 @@ import { User } from '../classes/User'
|
||||||
|
|
||||||
import prisma from '../prisma'
|
import prisma from '../prisma'
|
||||||
|
|
||||||
import { updateDevicesInfo } from '../utils/wifiUtils'
|
|
||||||
|
|
||||||
const parseSAMAccountName = sAMAccountName =>
|
const parseSAMAccountName = sAMAccountName =>
|
||||||
sAMAccountName ? sAMAccountName.replace('.', ' ') : ''
|
sAMAccountName ? sAMAccountName.replace('.', ' ') : ''
|
||||||
|
|
||||||
|
@ -75,20 +73,7 @@ const Query = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async stats() {
|
async stats() {
|
||||||
return {
|
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() } }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async wifiDevices(_, { identifiedOnly, nonIdentifiedOnly }) {
|
async wifiDevices(_, { identifiedOnly, nonIdentifiedOnly }) {
|
||||||
|
@ -149,7 +134,7 @@ const Query = {
|
||||||
a.wifiDevices[0].lastSeen > b.wifiDevices[0].lastSeen ? -1 : 1
|
a.wifiDevices[0].lastSeen > b.wifiDevices[0].lastSeen ? -1 : 1
|
||||||
)
|
)
|
||||||
|
|
||||||
return sortedUserPresences.slice(0, 100)
|
return sortedUserPresences.slice(0, 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
41
server/src/resolvers/Stats.js
Normal file
41
server/src/resolvers/Stats.js
Normal file
|
@ -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 }
|
|
@ -6,6 +6,7 @@ import { User } from './User'
|
||||||
import { Group } from './Group'
|
import { Group } from './Group'
|
||||||
import { ResetToken } from './ResetToken'
|
import { ResetToken } from './ResetToken'
|
||||||
import { WifiDevice } from './WifiDevice'
|
import { WifiDevice } from './WifiDevice'
|
||||||
|
import { Stats } from './Stats'
|
||||||
|
|
||||||
const resolvers = {
|
const resolvers = {
|
||||||
Query,
|
Query,
|
||||||
|
@ -14,7 +15,8 @@ const resolvers = {
|
||||||
User,
|
User,
|
||||||
Group,
|
Group,
|
||||||
ResetToken,
|
ResetToken,
|
||||||
WifiDevice
|
WifiDevice,
|
||||||
|
Stats
|
||||||
}
|
}
|
||||||
|
|
||||||
export { resolvers }
|
export { resolvers }
|
||||||
|
|
|
@ -144,6 +144,9 @@ const typeDefs = gql`
|
||||||
tokenCountUsed: Int!
|
tokenCountUsed: Int!
|
||||||
tokenCountExpired: Int!
|
tokenCountExpired: Int!
|
||||||
tokenCountNotUsed: Int!
|
tokenCountNotUsed: Int!
|
||||||
|
onlineUsers: Int!
|
||||||
|
offlineUsers: Int!
|
||||||
|
totalUsers: Int!
|
||||||
}
|
}
|
||||||
|
|
||||||
type WifiDevice {
|
type WifiDevice {
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
/>
|
/>
|
||||||
</v-toolbar>
|
</v-toolbar>
|
||||||
|
|
||||||
|
<div v-if="stats" class="text-center mb-2">
|
||||||
|
{{ stats.onlineUsers }} usuários online.
|
||||||
|
</div>
|
||||||
|
|
||||||
<UserPresenceStatusList
|
<UserPresenceStatusList
|
||||||
:user-presences="pagedUserPresences"
|
:user-presences="pagedUserPresences"
|
||||||
:loading="$apollo.queries.userPresence.loading && !userPresence"
|
:loading="$apollo.queries.userPresence.loading && !userPresence"
|
||||||
|
@ -86,6 +90,16 @@ export default {
|
||||||
},
|
},
|
||||||
debounce: 250
|
debounce: 250
|
||||||
},
|
},
|
||||||
|
stats: {
|
||||||
|
query: gql`
|
||||||
|
query {
|
||||||
|
stats {
|
||||||
|
onlineUsers
|
||||||
|
offlineUsers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
},
|
||||||
$subscribe: {
|
$subscribe: {
|
||||||
userPresenceUpdated: {
|
userPresenceUpdated: {
|
||||||
query: gql`
|
query: gql`
|
||||||
|
@ -95,6 +109,7 @@ export default {
|
||||||
`,
|
`,
|
||||||
result() {
|
result() {
|
||||||
this.$apollo.queries.userPresence.refresh()
|
this.$apollo.queries.userPresence.refresh()
|
||||||
|
this.$apollo.queries.stats.refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user