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)
}

View file

@ -61,7 +61,7 @@ function upsert (t, dbTx, preProcessedTx) {
function insert (t, tx) {
const dbTx = massage(tx)
const sql = pgp.helpers.insert(dbTx, null, 'cash_in_txs') + ' returning *'
return t.one(sql)
return t.$one(sql)
.then(toObj)
}
@ -72,7 +72,7 @@ function update (t, tx, changes) {
const sql = pgp.helpers.update(dbChanges, null, 'cash_in_txs') +
pgp.as.format(' where id=$1', [tx.id]) + ' returning *'
return t.one(sql)
return t.$one(sql)
.then(toObj)
}

View file

@ -69,7 +69,7 @@ function logAction (rec, tx) {
const sql = pgp.helpers.insert(action, null, 'cash_in_actions')
return db.none(sql)
return db.$none(sql)
.then(_.constant(rec))
}
@ -77,7 +77,7 @@ function logActionById (action, _rec, txId) {
const rec = _.assign(_rec, { action, tx_id: txId })
const sql = pgp.helpers.insert(rec, null, 'cash_in_actions')
return db.none(sql)
return db.$none(sql)
}
function checkForBlacklisted (tx) {
@ -165,7 +165,7 @@ function monitorPending (settings) {
.catch(logger.error)
}
return db.any(sql, [PENDING_INTERVAL, MAX_PENDING])
return db.$any(sql, [PENDING_INTERVAL, MAX_PENDING])
.then(rows => pEachSeries(rows, row => processPending(row)))
.catch(logger.error)
}
@ -182,7 +182,7 @@ function cancel (txId) {
return pgp.helpers.update(updateRec, null, 'cash_in_txs') +
pgp.as.format(' where id=$1', [txId])
})
.then(sql => db.result(sql, false))
.then(sql => db.$result(sql, false))
.then(res => {
if (res.rowCount !== 1) throw new Error('No such tx-id')
})