fix: use db tx to chain queries

This commit is contained in:
José Oliveira 2021-03-30 14:52:40 +01:00 committed by Josh Harvey
parent b5c2114cbf
commit d9ffca8a35

View file

@ -9,10 +9,12 @@ function createCashboxBatch (rec) {
cash_in_txs.device_id = $2 AND
bills.cashbox_batch_id IS NULL
`
return db.oneOrNone(sql, [rec.deviceId])
.then(res => {
return db.oneOrNone(sql2, [res.id, res.device_id])
return db.tx(async t => {
const newBatch = await t.oneOrNone(sql, [rec.deviceId])
return t.oneOrNone(sql2, [newBatch.id, newBatch.device_id])
})
.then(data => data)
.catch(error => error)
}
module.exports = { createCashboxBatch }