WIPP
This commit is contained in:
parent
bef0a8d98d
commit
0bf54fa1d8
7 changed files with 115 additions and 14 deletions
13
lib/tx.js
13
lib/tx.js
|
|
@ -8,12 +8,12 @@ function postCashIn (tx) {
|
|||
|
||||
function transaction (t) {
|
||||
const sql = 'select * from cash_in_txs where id=$1'
|
||||
return t.one(sql, [tx.id])
|
||||
return t.oneOrNone(sql, [tx.id])
|
||||
.then(row => {
|
||||
const newTx = executeTxChange(tx, row)
|
||||
const newTx = executeCashInTxChange(tx, row)
|
||||
|
||||
if (row) return updateCashOutTx(newTx)
|
||||
insertCashOutTx(newTx)
|
||||
if (row) return updateCashInTx(newTx)
|
||||
insertCashInTx(newTx)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -24,13 +24,14 @@ function postCashIn (tx) {
|
|||
}
|
||||
|
||||
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)
|
||||
throw new Error('No such tx direction: %s', tx.direction)
|
||||
|
||||
return Promise.reject(new Error('No such tx direction: %s', tx.direction))
|
||||
}
|
||||
|
||||
module.exports = {post}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue