From fb4267b0d5635e2e42eb4428526824a8c0adcdfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Wed, 21 Apr 2021 18:33:03 +0100 Subject: [PATCH] fix: customer history should no longer include txs which timedout or were cancelled --- lib/tx.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/tx.js b/lib/tx.js index bbb90ba6..063aa45f 100644 --- a/lib/tx.js +++ b/lib/tx.js @@ -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`])