[codex] Validate zap leaderboard filters - #381
Conversation
Greptile SummaryThis PR adds input validation to
Confidence Score: 5/5This PR is safe to merge; the added validation is a strict subset of the existing accepted values and the early returns do not alter any happy-path logic. Both changed files are narrow and self-contained. The allowlists in route.ts match the values documented in the JSDoc comment and used in the route's own conditional branches, so there is no risk of rejecting previously valid inputs. The tests cover the two new code paths, confirm no DB calls leak through, and are correctly isolated by vi.clearAllMocks() in beforeEach. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[GET /api/leaderboard/zaps] --> B[Parse period, sort, limit]
B --> C{period valid?\nall / month / week}
C -- No --> D[400 Invalid period]
C -- Yes --> E{sort valid?\nreceived / sent}
E -- No --> F[400 Invalid sort]
E -- Yes --> G[createServiceClient]
G --> H[Query zaps table\nwith date filter]
H --> I{DB error?}
I -- Yes --> J[500 error]
I -- No --> K[Aggregate by user]
K --> L[Sort + slice top N]
L --> M{Any results?}
M -- No --> N[200 empty leaderboard]
M -- Yes --> O[Fetch profiles]
O --> P[200 leaderboard response]
Reviews (1): Last reviewed commit: "Validate zap leaderboard filters" | Re-trigger Greptile |
Fixes #379.
Summary:
periodvalues on/api/leaderboard/zapsbefore querying Supabasesortvalues instead of silently falling back to received zapsValidation: