WIPP
This commit is contained in:
parent
0bf54fa1d8
commit
30071151ff
6 changed files with 107 additions and 242 deletions
35
lib/tx.js
35
lib/tx.js
|
|
@ -1,35 +1,8 @@
|
|||
const db = require('./db')
|
||||
const pgp = require('pg-promise')()
|
||||
const CashInTx = require('./cash-in-tx')
|
||||
|
||||
function postCashIn (tx) {
|
||||
const TransactionMode = pgp.txMode.TransactionMode
|
||||
const isolationLevel = pgp.txMode.isolationLevel
|
||||
const tmSRD = new TransactionMode({tiLevel: isolationLevel.serializable})
|
||||
|
||||
function transaction (t) {
|
||||
const sql = 'select * from cash_in_txs where id=$1'
|
||||
return t.oneOrNone(sql, [tx.id])
|
||||
.then(row => {
|
||||
const newTx = executeCashInTxChange(tx, row)
|
||||
|
||||
if (row) return updateCashInTx(newTx)
|
||||
insertCashInTx(newTx)
|
||||
})
|
||||
}
|
||||
|
||||
transaction.txMode = tmSRD
|
||||
|
||||
return db.tx(transaction)
|
||||
// retry failed
|
||||
}
|
||||
|
||||
function postCashOut (tx) {
|
||||
throw new Error('not implemented')
|
||||
}
|
||||
|
||||
function post (tx) {
|
||||
if (tx.direction === 'cashIn') return postCashIn(tx)
|
||||
if (tx.direction === 'cashOut') return postCashOut(tx)
|
||||
function post (tx, pi) {
|
||||
if (tx.direction === 'cashIn') return CashInTx.post(tx, pi)
|
||||
if (tx.direction === 'cashOut') throw new Error('not implemented')
|
||||
|
||||
return Promise.reject(new Error('No such tx direction: %s', tx.direction))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue