fix: correct calculation to find expired transactions on customer history
This commit is contained in:
parent
1c8098fe73
commit
146f67a0b7
1 changed files with 17 additions and 12 deletions
15
lib/tx.js
15
lib/tx.js
|
|
@ -3,6 +3,9 @@ const db = require('./db')
|
|||
const BN = require('./bn')
|
||||
const CashInTx = require('./cash-in/cash-in-tx')
|
||||
const CashOutTx = require('./cash-out/cash-out-tx')
|
||||
const T = require('./time')
|
||||
|
||||
const REDEEMABLE_AGE = T.day
|
||||
|
||||
function process (tx, pi) {
|
||||
const mtx = massage(tx, pi)
|
||||
|
|
@ -65,21 +68,23 @@ function cancel (txId) {
|
|||
}
|
||||
|
||||
function customerHistory (customerId, thresholdDays) {
|
||||
const sql = ` SELECT txIn.id, txIn.created, txIn.fiat, 'cashIn' AS direction
|
||||
const sql = `SELECT * FROM (
|
||||
SELECT txIn.id, txIn.created, txIn.fiat, 'cashIn' AS direction,
|
||||
((NOT txIn.send_confirmed) AND (txIn.created <= now() - interval $3)) AS expired
|
||||
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
|
||||
SELECT txOut.id, txOut.created, txOut.fiat, 'cashOut' AS direction,
|
||||
(extract(epoch FROM (now() - greatest(txOut.created, txOut.confirmed_at))) * 1000) >= $4 AS expired
|
||||
FROM cash_out_txs txOut
|
||||
WHERE txOut.customer_id = $1
|
||||
AND txOut.created > now() - interval $2
|
||||
AND timedout IS false
|
||||
AND error_code IS DISTINCT FROM 'operatorCancel'
|
||||
ORDER BY created;`
|
||||
) ch WHERE NOT ch.expired ORDER BY ch.created`
|
||||
|
||||
const days = _.isNil(thresholdDays) ? 0 : thresholdDays
|
||||
return db.any(sql, [customerId, `${days} days`])
|
||||
return db.any(sql, [customerId, `${days} days`, '60 minutes', REDEEMABLE_AGE])
|
||||
}
|
||||
|
||||
module.exports = {post, cancel, customerHistory}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue