From 6fa3ebd8c15f94fb892b1eff9ba36493a80665a9 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Mon, 19 May 2025 13:42:26 +0100 Subject: [PATCH] fix: customer history with large threshold days --- packages/server/lib/tx.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/server/lib/tx.js b/packages/server/lib/tx.js index 5b0cf010..5d1de2f0 100644 --- a/packages/server/lib/tx.js +++ b/packages/server/lib/tx.js @@ -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]) }