From 699fcf7e5c2f17adcef730951ad013ec3f7d4277 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 25 Nov 2026 15:11:52 -0700 Subject: funds: include archived and pre-rotation history in GET /fund/:id A fund's older payments live in the archive, and funds whose id was rotated keep that history under their previous id, so the fund page only showed the most recent entries. Merge the live and archived lists for both ids (fund:rotatedFrom: maps a rotated fund back to its previous id) and sort newest first. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6W9CsdxmhFrfaKNVHU --- routes/payments.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'routes/payments.ts') diff --git a/routes/payments.ts b/routes/payments.ts index f9be4c34..86f34cc5 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -302,15 +302,31 @@ export default { if (typeof amount === "undefined" || amount === null) return bail(res, "fund not found"); - let payments = (await db.lRange(`fund:${fid}:payments`, 0, -1)) || []; - payments = await Promise.all(payments.map((hash) => gf(`payment:${hash}`))); + // Older history was moved to the archive, and funds rotated on 2026-08-25 + // keep their archived history under the pre-rotation id + // (fund:rotatedFrom: -> old, backfilled from fund:rotated:*). + const oldId = fid !== id ? id : await g(`fund:rotatedFrom:${fid}`); + const lists = await Promise.all([ + db.lRange(`fund:${fid}:payments`, 0, -1), + archive.lRange(`fund:${fid}:payments`, 0, -1), + ...(oldId + ? [ + db.lRange(`fund:${oldId}:payments`, 0, -1), + archive.lRange(`fund:${oldId}:payments`, 0, -1), + ] + : []), + ]); + let payments: any[] = [...new Set(lists.flatMap((l) => l || []))]; + payments = await Promise.all(payments.map((pid) => gf(`payment:${pid}`))); + + payments = payments + .filter((p) => p) + .sort((a, b) => b.created - a.created); await Promise.all( payments.map(async (p: any) => (p.user = await getUser(p.uid, fields))), ); - payments = payments.filter((p) => p); - const authorization = await g(`authorization:${fid}`); res.send({ amount, -- cgit v1.2.3