From 79c048ccf50705fb786c885baf66f713ae70cf9c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 28 Nov 2024 09:07:27 -0800 Subject: set last time for payments --- routes/payments.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'routes') diff --git a/routes/payments.ts b/routes/payments.ts index 5a6eba91..46728578 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -96,7 +96,9 @@ export default { if (limit) limit = parseInt(limit); offset = parseInt(offset) || 0; - let payments = (await db.lRange(`${aid || id}:payments`, 0, -1)) || []; + const range = start || end ? -1 : limit - 1; + let payments = (await db.lRange(`${aid || id}:payments`, 0, range)) || []; + payments = ( await Promise.all( payments.map(async (pid) => { @@ -115,8 +117,6 @@ export default { .filter((p) => p) .sort((a, b) => b.created - a.created); - const count = payments.length; - const fn = (a, b) => ({ ...a, [b.currency]: { @@ -146,6 +146,7 @@ export default { const incoming = payments.filter((p: any) => p.amount > 0).reduce(fn, {}); const outgoing = payments.filter((p: any) => p.amount < 0).reduce(fn, {}); + const { length: count } = payments; if (limit) payments = payments.slice(offset, offset + limit); res.send({ payments, count, incoming, outgoing }); -- cgit v1.2.3