Skip to content

fix: roadmap filters returning 400 due to limit validation mismatch #311

Merged
Sachinchaurasiya360 merged 1 commit into
Sachinchaurasiya360:mainfrom
vidhiii1711:fix/roadmap-filter-limit-validation
May 21, 2026
Merged

fix: roadmap filters returning 400 due to limit validation mismatch #311
Sachinchaurasiya360 merged 1 commit into
Sachinchaurasiya360:mainfrom
vidhiii1711:fix/roadmap-filter-limit-validation

Conversation

@vidhiii1711
Copy link
Copy Markdown

@vidhiii1711 vidhiii1711 commented May 17, 2026

Summary

The roadmap filter feature was broken — every request to /api/roadmaps
was returning 400 Bad Request, so filters for level, tag, category and
search never worked. After reading through the codebase, the root cause
was a mismatch between what the frontend sends and what the backend
validation allows. The frontend sends limit=100 but the validation
schema had max(50), so every request was rejected before even reaching
the Prisma query or the database. Fixes #194

Changes

  • server/src/module/roadmap/roadmap.validation.ts — bumped limit max
    from 50 to 100 to match what the frontend actually sends
  • server/src/module/roadmap/roadmap.service.ts — replaced separate
    has conditions for tag and category with a single hasSome, so
    filtering by both doesn't require a roadmap to have both values
    simultaneously in its tags array

How to test

  1. Clone the repo and run npm run dev in the server folder
  2. Open the roadmaps page in the browser
  3. Open the Network tab in browser devtools
  4. Click any filter (Level, Tag, or Category)
  5. Before this fix: every request returns 400 Bad Request
  6. After this fix: requests return 200 with correctly filtered results

Screenshots (if UI changes)

No UI changes

Note

While testing locally I noticed the seed script
(src/database/seeds/seed.ts) doesn't seed any roadmap data, even
though two JSON files exist at src/module/roadmap/seed/
(ai-engineer.json, full-stack.json). So the roadmaps page will show
"no results" on a fresh local setup even after this fix. Happy to raise
a follow-up PR to wire those JSON files into the seed script if needed.

Summary by CodeRabbit

  • Improvements
    • Increased maximum query results limit from 50 to 100 items per request. Default page size remains 20 items.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

📝 Walkthrough

Walkthrough

The roadmap list query is improved with two complementary changes: the validation constraint on the result limit is increased from 50 to 100 to allow larger result sets, and the filtering logic is refactored to consolidate multiple tag/category filter values into a single array-based Prisma filter condition.

Changes

Roadmap list query improvements

Layer / File(s) Summary
Query limit constraint update
server/src/module/roadmap/roadmap.validation.ts
The listQuerySchema validation increases the maximum limit parameter from 50 to 100, preserving integer coercion and the default of 20.
Tag/category filtering refactoring
server/src/module/roadmap/roadmap.service.ts
listPublishedRoadmaps consolidates opts.tag and opts.category into a single tagFilters array and applies a unified Prisma tags.hasSome filter when values are present.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

bug

Poem

A rabbit hops through roadmap rows,
With filters consolidated in arrays so fine,
The limit now stretches to one hundred and more—
More results to fetch, more paths to explore! 🐰📚

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing a validation mismatch causing 400 errors on roadmap filter requests by aligning the limit constraint with frontend expectations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
server/src/module/roadmap/roadmap.validation.ts (1)

52-52: 💤 Low value

Remove commented-out code.

The old validation constraint is left as a comment. Remove it to keep the codebase clean.

♻️ Proposed cleanup
- // limit: z.coerce.number().int().min(1).max(50).default(20),
  limit: z.coerce.number().int().min(1).max(100).default(20),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/module/roadmap/roadmap.validation.ts` at line 52, Remove the
leftover commented-out validation line "// limit:
z.coerce.number().int().min(1).max(50).default(20)," from the roadmap validation
file so the codebase stays clean; locate the commented fragment referencing
"limit" and "z.coerce.number()" in roadmap.validation.ts and delete that single
commented line (no other changes).
server/src/module/roadmap/roadmap.service.ts (1)

93-98: 💤 Low value

Remove commented-out code.

The previous filtering logic is left as a comment block. Remove it to keep the codebase clean.

♻️ Proposed cleanup
- // if (opts.tag) {
- //   andConditions.push({ tags: { has: opts.tag } });
- // }
- // if (opts.category) {
- //   andConditions.push({ tags: { has: opts.category } });
- // }
  const tagFilters: string[] = [];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/module/roadmap/roadmap.service.ts` around lines 93 - 98, Remove
the dead commented filtering code in roadmap.service.ts: delete the commented
block that references opts.tag/opts.category and pushes to andConditions (the
three commented lines using "{ tags: { has: ... } }") so the method (where
andConditions is built) contains only active logic; ensure no leftover TODOs or
commented logic remain and run tests/lint to verify clean build.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@server/src/module/roadmap/roadmap.service.ts`:
- Around line 93-98: Remove the dead commented filtering code in
roadmap.service.ts: delete the commented block that references
opts.tag/opts.category and pushes to andConditions (the three commented lines
using "{ tags: { has: ... } }") so the method (where andConditions is built)
contains only active logic; ensure no leftover TODOs or commented logic remain
and run tests/lint to verify clean build.

In `@server/src/module/roadmap/roadmap.validation.ts`:
- Line 52: Remove the leftover commented-out validation line "// limit:
z.coerce.number().int().min(1).max(50).default(20)," from the roadmap validation
file so the codebase stays clean; locate the commented fragment referencing
"limit" and "z.coerce.number()" in roadmap.validation.ts and delete that single
commented line (no other changes).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d21adb91-015d-4aec-9ece-f0e4558c64d4

📥 Commits

Reviewing files that changed from the base of the PR and between 3552efa and ad034c8.

📒 Files selected for processing (2)
  • server/src/module/roadmap/roadmap.service.ts
  • server/src/module/roadmap/roadmap.validation.ts

@Abfa41 Abfa41 added level:intermediate Requires moderate project understanding type:bug Bug fixes gssoc:approved Approved for GSSoC scoring labels May 18, 2026
@Sachinchaurasiya360 Sachinchaurasiya360 merged commit f71b48d into Sachinchaurasiya360:main May 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC scoring level:intermediate Requires moderate project understanding type:bug Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Roadmaps fail to load when filters are applied

3 participants