fix: customer history should no longer include txs which timedout or were cancelled

This commit is contained in:
Sérgio Salgado 2021-04-21 18:33:03 +01:00 committed by Josh Harvey
parent d7f0b1226c
commit fb4267b0d5

View file

@ -65,14 +65,17 @@ function cancel (txId) {
}
function customerHistory (customerId, thresholdDays) {
const sql = ` select txIn.id, txIn.created, txIn.fiat, 'cashIn' as direction from cash_in_txs txIn
where txIn.customer_id = $1
and txIn.created > now() - interval $2
union
select txOut.id, txOut.created, txOut.fiat, 'cashOut' as direction from cash_out_txs txOut
where txOut.customer_id = $1
and txOut.created > now() - interval $2
order by created;`
const sql = ` SELECT txIn.id, txIn.created, txIn.fiat, 'cashIn' AS direction
FROM cash_in_txs txIn
WHERE txIn.customer_id = $1
AND txIn.created > now() - interval $2
UNION
SELECT txOut.id, txOut.created, txOut.fiat, 'cashOut' AS direction
FROM cash_out_txs txOut
WHERE txOut.customer_id = $1
AND txOut.created > now() - interval $2
AND (timedout = true OR error_code != 'operatorCancel')
ORDER BY created;`
const days = _.isNil(thresholdDays) ? 0 : thresholdDays
return db.any(sql, [customerId, `${days} days`])