fix: use database tx to chain queries
This commit is contained in:
parent
ce48360f04
commit
4bf972b995
1 changed files with 9 additions and 5 deletions
|
|
@ -511,15 +511,15 @@ function plugins (settings, deviceId) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function recordTradeAndTx (tradeId, internalTxIdList) {
|
function recordTradeAndTx (tradeId, internalTxIdList, dbTx) {
|
||||||
_.map(internalTxId => {
|
_.map(internalTxId => {
|
||||||
let entry = { trade_id: tradeId }
|
let entry = { trade_id: tradeId }
|
||||||
if (internalTxId.direction === 'cashIn') {
|
if (internalTxId.direction === 'cashIn') {
|
||||||
entry.cash_in_tx_id = internalTxId.txId
|
entry.cash_in_tx_id = internalTxId.txId
|
||||||
return db.none(pgp.helpers.insert(entry, null, 'cashin_tx_trades'))
|
return dbTx.none(pgp.helpers.insert(entry, null, 'cashin_tx_trades'))
|
||||||
}
|
}
|
||||||
entry.cash_out_tx_id = internalTxId.txId
|
entry.cash_out_tx_id = internalTxId.txId
|
||||||
return db.none(pgp.helpers.insert(entry, null, 'cashout_tx_trades'))
|
return dbTx.none(pgp.helpers.insert(entry, null, 'cashout_tx_trades'))
|
||||||
}, internalTxIdList)
|
}, internalTxIdList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -553,8 +553,12 @@ function plugins (settings, deviceId) {
|
||||||
)
|
)
|
||||||
const tradeEntry = massage(_tradeEntry, error)
|
const tradeEntry = massage(_tradeEntry, error)
|
||||||
const sql = pgp.helpers.insert(tradeEntry, null, 'trades') + 'RETURNING *'
|
const sql = pgp.helpers.insert(tradeEntry, null, 'trades') + 'RETURNING *'
|
||||||
return db.oneOrNone(sql)
|
db.tx(async t => {
|
||||||
.then(newTrade => recordTradeAndTx(newTrade.id, _tradeEntry.internalTxIdList))
|
const newTrade = await t.oneOrNone(sql)
|
||||||
|
return recordTradeAndTx(newTrade.id, _tradeEntry.internalTxIdList, t)
|
||||||
|
})
|
||||||
|
.then(data => data)
|
||||||
|
.catch(error => error)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMessage (rec) {
|
function sendMessage (rec) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue