diff --git a/lib/cashbox-batches.js b/lib/cashbox-batches.js index a6177cc1..67cd027c 100644 --- a/lib/cashbox-batches.js +++ b/lib/cashbox-batches.js @@ -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 }