fix(leaderboard): clamp zap limit values#333
Conversation
Greptile SummaryThis PR fixes an input-validation gap in the zap leaderboard endpoint by clamping the
Confidence Score: 5/5Safe to merge — the change is a narrow, well-contained input-validation fix with no impact on any other code path. The limit-clamping logic is correct: NaN from non-numeric input is caught by No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[GET /api/leaderboard/zaps] --> B[Parse limit param]
B --> C{parseInt result\nfinite?}
C -- Yes --> D["Math.min(Math.max(n, 1), 50)"]
C -- No / NaN --> E[limit = 25 default]
D --> F[Fetch zaps from Supabase]
E --> F
F --> G{dateFilter set?}
G -- period=week/month --> H[query.gte created_at]
G -- period=all --> I[query unchanged]
H --> J[Await query]
I --> J
J --> K[Aggregate per-user stats]
K --> L[Sort by total_sats, slice 0..limit]
L --> M{Results empty?}
M -- Yes --> N[Return leaderboard: empty]
M -- No --> O[Fetch profiles by user IDs]
O --> P[Build ranked leaderboard]
P --> Q[Return JSON response]
Reviews (2): Last reviewed commit: "test(leaderboard): make zap mock chainab..." | Re-trigger Greptile |
|
Addressed the Greptile notes in d4d37be: cleaned the garbled JSDoc dash and made the zaps test mock chainable so future period-filter tests can call |
Summary
/api/leaderboard/zapslimit query values to the supported 1..50 rangeFixes #332.
Verification
limit=-5andlimit=abc.npm/package runner available, so I could not execute the Vitest file here.