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

@ -9,7 +9,7 @@ function pullToken (token) {
const sql = `delete from pairing_tokens
where token=$1
returning name, created < now() - interval '1 hour' as expired`
return db.one(sql, [token])
return db.$one(sql, [token])
}
function unpair (deviceId) {
@ -17,7 +17,7 @@ function unpair (deviceId) {
const deleteMachinePings = 'delete from machine_pings where device_id=$1'
// TODO new-admin: We should remove all configs related to that device. This can get tricky.
return Promise.all([db.none(sql, [deviceId]), db.none(deleteMachinePings, [deviceId])])
return Promise.all([db.$none(sql, [deviceId]), db.$none(deleteMachinePings, [deviceId])])
}
function pair (token, deviceId, machineModel) {
@ -29,7 +29,7 @@ function pair (token, deviceId, machineModel) {
on conflict (device_id)
do update set paired=TRUE, display=TRUE`
return db.none(insertSql, [deviceId, r.name])
return db.$none(insertSql, [deviceId, r.name])
.then(() => true)
})
.catch(err => {
@ -51,7 +51,7 @@ function authorizeCaDownload (caToken) {
function isPaired (deviceId) {
const sql = 'select device_id, name from devices where device_id=$1 and paired=TRUE'
return db.oneOrNone(sql, [deviceId])
return db.$oneOrNone(sql, [deviceId])
.then(row => row && row.device_id === deviceId ? row.name : false)
}