Merge pull request #1857 from RafaelTaranto/fix/customer-history-query

LAM-1392 fix: customer history with large threshold days
This commit is contained in:
Rafael Taranto 2025-05-23 16:03:50 +01:00 committed by GitHub
commit 6f4a0b775b

View file

@ -8,6 +8,7 @@ const T = require('./time')
// FP operations on Postgres result in very big errors.
// E.g.: 1853.013808 * 1000 = 1866149.494
const REDEEMABLE_AGE = T.day / 1000
const MAX_THRESHOLD_DAYS = 365 * 50 // 50 years maximum
function process(tx, pi) {
const mtx = massage(tx)
@ -92,7 +93,9 @@ function customerHistory(customerId, thresholdDays) {
AND fiat > 0
) ch WHERE NOT ch.expired ORDER BY ch.created`
const days = _.isNil(thresholdDays) ? 0 : thresholdDays
const days = _.isNil(thresholdDays)
? 0
: Math.min(thresholdDays, MAX_THRESHOLD_DAYS)
return db.any(sql, [customerId, `${days} days`, '60 minutes', REDEEMABLE_AGE])
}