fix(reviews): clamp public user pagination params#286
Conversation
Greptile SummaryThis PR fixes two related problems in the public user-reviews endpoint: invalid pagination params (
Confidence Score: 4/5Safe to merge; the core logic change is correct and well-tested, with one minor design concern worth revisiting. The param-clamping fix and the average-rating-over-all-reviews fix are both correct. The only notable concern is that the new route.ts — the unbounded Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Route as GET /api/users/[username]/reviews
participant DB as Supabase
Client->>Route: "GET ?limit=X&offset=Y"
Note over Route: clamp limit (1-50, default 10)<br/>clamp offset (>=0, default 0)
Route->>DB: profiles.select("id").eq("username", username).single()
DB-->>Route: "profile | null"
alt profile not found
Route-->>Client: 404 User not found
else profile found
Route->>DB: reviews.select("rating").eq("reviewee_id", id)
DB-->>Route: allRatings[]
Route->>DB: "reviews.select(*).eq(...).order(...).range(offset, offset+limit-1) {count: exact}"
DB-->>Route: reviews[], count
Note over Route: averageRating = sum(allRatings) / allRatings.length
Route-->>Client: "200 { data, summary, pagination }"
end
Reviews (2): Last reviewed commit: "test(reviews): cover summary rating sour..." | Re-trigger Greptile |
|
Follow-up pushed in ed592f7: addressed Greptile's average-rating finding by computing the summary from an unpaginated rating query, while keeping the paginated review list unchanged. The test now verifies the summary uses all ratings, not only the current page.\n\nValidation run locally:\n- corepack pnpm test -- src/app/api/users/[username]/reviews/route.test.ts\n- node_modules\.bin\tsc.CMD -p tsconfig.json --noEmit |
Summary
Closes #285
Validation
Submitted for the ugig bounty: I will pay for every bug fix found and PR submitted that fixes it.
Solana wallet for bounty payout:
Dy4yMkjCfupxaURt6iTMUrxqSDEmAJPPkKF66QahxJZD