fix: use db tx to chain queries
This commit is contained in:
parent
b5c2114cbf
commit
d9ffca8a35
1 changed files with 6 additions and 4 deletions
|
|
@ -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 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue