Chore: move tx code into atomic function

This commit is contained in:
csrapr 2021-04-15 14:17:42 +01:00 committed by Josh Harvey
parent 8cd1389de3
commit 4f12bcf4cf
4 changed files with 12 additions and 14 deletions

View file

@ -1,6 +1,7 @@
const _ = require('lodash/fp')
const pgp = require('pg-promise')()
const db = require('../db')
const E = require('../error')
const cashInLow = require('./cash-in-low')
@ -8,6 +9,9 @@ const cashInLow = require('./cash-in-low')
module.exports = { atomic }
function atomic (machineTx, pi) {
const TransactionMode = pgp.txMode.TransactionMode
const isolationLevel = pgp.txMode.isolationLevel
const mode = new TransactionMode({ tiLevel: isolationLevel.serializable })
function transaction (t) {
const sql = 'select * from cash_in_txs where id=$1'
const sql2 = 'select * from bills where cash_in_txs_id=$1'
@ -29,7 +33,7 @@ function atomic (machineTx, pi) {
})
})
}
return transaction
return db.tx({ mode }, transaction)
}
function insertNewBills (t, billRows, machineTx) {