Some refactoring

This commit is contained in:
Douglas Barone 2020-11-06 20:22:26 -04:00
parent 7baa5097f9
commit 77c5e7117b
3 changed files with 17 additions and 15 deletions

View File

@ -1,7 +1,7 @@
version: '3' version: '3'
services: services:
postgres: postgres:
image: postgres image: postgres:latest
restart: 'no' restart: 'no'
environment: environment:
POSTGRES_USER: prisma POSTGRES_USER: prisma
@ -12,7 +12,7 @@ services:
- '5432:5432' - '5432:5432'
pgadmin: pgadmin:
image: dpage/pgadmin4 image: dpage/pgadmin4:latest
restart: 'no' restart: 'no'
environment: environment:
PGADMIN_DEFAULT_EMAIL: 'admin@pg.com' PGADMIN_DEFAULT_EMAIL: 'admin@pg.com'

View File

@ -21,9 +21,8 @@ class ResetToken {
throw new Error('Apenas estudantes podem utilizar tokens') throw new Error('Apenas estudantes podem utilizar tokens')
const token = uuid() const token = uuid()
const expiration = moment(new Date()) // TODO: replace momentJS
.add(3, 'days') const expiration = moment(new Date()).add(3, 'days').toDate()
.toDate()
console.log(expiration) console.log(expiration)
@ -84,9 +83,11 @@ class ResetToken {
throw new Error('Token inválido, já usado ou expirado') throw new Error('Token inválido, já usado ou expirado')
} }
const user = await prisma.resetToken.findOne({ const user = await prisma.resetToken
where: { id: resetToken.id } .findOne({
}).user() where: { id: resetToken.id }
})
.user()
await replacePassword(user.sAMAccountName, newPassword) await replacePassword(user.sAMAccountName, newPassword)

View File

@ -82,8 +82,11 @@ const Query = {
async stats() { async stats() {
return { return {
//TODO: count
tokenCountTotal: prisma.resetToken.count(), tokenCountTotal: prisma.resetToken.count(),
tokenCountUsed: 0, tokenCountUsed: prisma.resetToken.count({
where: { NOT: { usedAt: null } }
}),
tokenCountExpired: 0, tokenCountExpired: 0,
tokenCountNotUsed: 0 tokenCountNotUsed: 0
} }
@ -102,10 +105,10 @@ const Query = {
}) })
}, },
userPresence: async (_, { search }) => { userPresence: async (_, { search }) => {
// if (!search) { if (!search) {
// await updateDBWithOnlineDevices() await updateDBWithOnlineDevices()
// search = '' search = ''
// } }
const usersWithWifiDevices = await prisma.user.findMany({ const usersWithWifiDevices = await prisma.user.findMany({
include: { WifiDevice: true } include: { WifiDevice: true }
@ -130,8 +133,6 @@ const Query = {
) )
})) }))
console.dir(userPresences)
const sortedUserPresences = userPresences.sort((a, b) => const sortedUserPresences = userPresences.sort((a, b) =>
a.wifiDevices[0].lastSeen > b.wifiDevices[0].lastSeen ? -1 : 1 a.wifiDevices[0].lastSeen > b.wifiDevices[0].lastSeen ? -1 : 1
) )