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 => {
|
||||
let entry = { trade_id: tradeId }
|
||||
if (internalTxId.direction === 'cashIn') {
|
||||
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
|
||||
return db.none(pgp.helpers.insert(entry, null, 'cashout_tx_trades'))
|
||||
return dbTx.none(pgp.helpers.insert(entry, null, 'cashout_tx_trades'))
|
||||
}, internalTxIdList)
|
||||
}
|
||||
|
||||
|
|
@ -553,8 +553,12 @@ function plugins (settings, deviceId) {
|
|||
)
|
||||
const tradeEntry = massage(_tradeEntry, error)
|
||||
const sql = pgp.helpers.insert(tradeEntry, null, 'trades') + 'RETURNING *'
|
||||
return db.oneOrNone(sql)
|
||||
.then(newTrade => recordTradeAndTx(newTrade.id, _tradeEntry.internalTxIdList))
|
||||
db.tx(async t => {
|
||||
const newTrade = await t.oneOrNone(sql)
|
||||
return recordTradeAndTx(newTrade.id, _tradeEntry.internalTxIdList, t)
|
||||
})
|
||||
.then(data => data)
|
||||
.catch(error => error)
|
||||
}
|
||||
|
||||
function sendMessage (rec) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue