fix(pagination): clamp page/offset params in directory, notifications, and prompts - #299
Conversation
…ions, and prompts - Directory (profullstack#296): clamp page to minimum 1 to prevent negative offsets - Notifications (profullstack#297): clamp offset to minimum 0, limit to minimum 1 - Prompts (profullstack#298): clamp page to minimum 1 to prevent negative offsets Negative page/offset values were silently passed to Supabase .range() causing 500 errors.
Greptile SummaryThis PR fixes 500 errors in three API routes caused by negative
Confidence Score: 5/5Safe to merge — all three changes are small, targeted, and correct, with no new logic paths or side effects introduced. Each change is a single-line guard that correctly handles all edge cases: NaN from non-numeric strings, zero (which already triggered the default fallback), and negative values. The clamping order in notifications is correct, and the NaN fallbacks fire before the Math.max clamp, so no invalid value can slip through to Supabase. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming query param\npage / offset / limit] --> B{Parse numeric value}
B -->|parseInt / Number| C{Result is NaN?}
C -- Yes --> D[Apply fallback default\npage→1, limit→50, offset→0]
C -- No --> E[Use parsed value]
D --> F{Apply Math.max clamp}
E --> F
F -->|page: Math.max 1, val| G[page ≥ 1]
F -->|offset: Math.max 0, val| H[offset ≥ 0]
F -->|limit: Math.max 1 then Math.min 100| I[1 ≤ limit ≤ 100]
G --> J[offset = page - 1 × 20]
H --> K[Supabase .range offset, offset+limit-1]
I --> K
J --> K
K --> L[Safe DB query — no negative range values]
Reviews (1): Last reviewed commit: "fix(pagination): clamp page and offset p..." | Re-trigger Greptile |
Fixes #296, #297, #298.
Changes
GET /api/directory?page=-1— page is now clamped to minimum 1; negative values no longer compute a negative offsetGET /api/notifications?offset=-10— offset is now clamped to minimum 0; limit is clamped to minimum 1GET /api/prompts?page=-1— page is now clamped to minimum 1; same fix as directoryAll three followed the same pattern: unclamped
parseInt/Numberresults were passed directly to Supabase.range(), causing 500 database errors for negative inputs.