WIPP
This commit is contained in:
parent
f877f1f977
commit
bef0a8d98d
2 changed files with 44 additions and 9 deletions
36
lib/tx.js
Normal file
36
lib/tx.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const db = require('./db')
|
||||
const pgp = require('pg-promise')()
|
||||
|
||||
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.one(sql, [tx.id])
|
||||
.then(row => {
|
||||
const newTx = executeTxChange(tx, row)
|
||||
|
||||
if (row) return updateCashOutTx(newTx)
|
||||
insertCashOutTx(newTx)
|
||||
})
|
||||
}
|
||||
|
||||
transaction.txMode = tmSRD
|
||||
|
||||
return db.tx(transaction)
|
||||
// retry failed
|
||||
}
|
||||
|
||||
function postCashOut (tx) {
|
||||
|
||||
}
|
||||
|
||||
function post (tx) {
|
||||
if (tx.direction === 'cashIn') return postCashIn(tx)
|
||||
if (tx.direction === 'cashOut') return postCashOut(tx)
|
||||
throw new Error('No such tx direction: %s', tx.direction)
|
||||
}
|
||||
|
||||
module.exports = {post}
|
||||
Loading…
Add table
Add a link
Reference in a new issue