Chore: refactor to use new schema changing queries

This commit is contained in:
csrapr 2021-03-01 15:55:29 +00:00 committed by Josh Harvey
parent 304f792484
commit e6059be8d2
44 changed files with 185 additions and 171 deletions

View file

@ -7,7 +7,7 @@ function generateOTP (name) {
const sql = 'insert into one_time_passes (token, name) values ($1, $2)'
return db.none(sql, [otp, name])
return db.$none(sql, [otp, name])
.then(() => otp)
}
@ -16,7 +16,7 @@ function validateOTP (otp) {
where token=$1
returning name, created < now() - interval '1 hour' as expired`
return db.one(sql, [otp])
return db.$one(sql, [otp])
.then(r => ({success: !r.expired, expired: r.expired, name: r.name}))
.catch(() => ({success: false, expired: false}))
}
@ -29,7 +29,7 @@ function register (otp) {
const token = crypto.randomBytes(32).toString('hex')
const sql = 'insert into user_tokens (token, name) values ($1, $2)'
return db.none(sql, [token, r.name])
return db.$none(sql, [token, r.name])
.then(() => ({success: true, token: token}))
})
.catch(() => ({success: false, expired: false}))
@ -38,7 +38,7 @@ function register (otp) {
function authenticate (token) {
const sql = 'select token from user_tokens where token=$1'
return db.one(sql, [token]).then(() => true).catch(() => false)
return db.$one(sql, [token]).then(() => true).catch(() => false)
}
module.exports = {