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

@ -16,11 +16,11 @@ function atomic (machineTx, pi) {
const sql = 'select * from cash_in_txs where id=$1'
const sql2 = 'select * from bills where cash_in_txs_id=$1'
return t.oneOrNone(sql, [machineTx.id])
return t.$oneOrNone(sql, [machineTx.id])
.then(row => {
if (row && row.tx_version >= machineTx.txVersion) throw new E.StaleTxError('Stale tx')
return t.any(sql2, [machineTx.id])
return t.$any(sql2, [machineTx.id])
.then(billRows => {
const dbTx = cashInLow.toObj(row)
@ -47,9 +47,9 @@ function insertNewBills (t, billRows, machineTx) {
const sql2 = `update devices set cashbox = cashbox + $2
where device_id = $1`
return t.none(sql2, [deviceID, dbBills.length])
return t.$none(sql2, [deviceID, dbBills.length])
.then(() => {
return t.none(sql)
return t.$none(sql)
})
.then(() => bills)
}