Skip to content

fix: validate limit/offset query params on intent listing - #158

Open
Phantomcall wants to merge 1 commit into
stellar-vortex-protocol:mainfrom
Phantomcall:fix/pagination-nan-validation
Open

fix: validate limit/offset query params on intent listing#158
Phantomcall wants to merge 1 commit into
stellar-vortex-protocol:mainfrom
Phantomcall:fix/pagination-nan-validation

Conversation

@Phantomcall

Copy link
Copy Markdown

PR Description: Fix Pagination NaN Bug in IntentsController.list()

Issue Reference

Summary

IntentsController.list() was using parseInt() on raw query parameters (limitRaw, offsetRaw) without any validation. When a non-numeric value was provided (e.g., ?limit=abc), parseInt() returned NaN, which silently corrupted the pagination slice (intents.slice(offset, offset + limit)) instead of returning a clear 400 error.

Changes

New File: src/intents/dto/list-intents.dto.ts

Introduced a typed DTO for list query parameters using class-validator decorators consistent with the rest of the codebase:

  • limit: @IsInt(), @Min(1), @Max(100) — ensures the value is a valid integer between 1 and 100
  • offset: @IsInt(), @Min(0) — ensures the value is a valid non-negative integer
  • state, user, chain: @IsOptional(), @IsString() — optional string filters

Modified File: src/intents/intents.controller.ts

  • Changed list() method signature from individual @Query() parameters to a single @Query() dto: ListIntentsDto
  • Replaced Math.min(parseInt(limitRaw, 10), 100) and parseInt(offsetRaw, 10) with dto.limit and dto.offset
  • The global ValidationPipe (configured in main.ts with whitelist: true, transform: true) automatically validates the DTO and returns a 400 response with detailed error information when validation fails

Modified File: test/intents.e2e-spec.ts

Added two new e2e tests:

  1. GET /api/v1/intents with non-numeric limit returns 400 — Asserts that ?limit=abc returns HTTP 400 with error: "Validation failed" and an array of details
  2. GET /api/v1/intents with non-numeric offset returns 400 — Asserts that ?offset=xyz returns HTTP 400 with error: "Validation failed" and an array of details

Verification

  • npm run lint passes
  • npm run typecheck passes
  • npm test passes
  • npm run test:e2e passes (new e2e tests for non-numeric limit/offset)

Acceptance Criteria

  • Limit/offset moved into a proper DTO with @IsInt()/@Min()/@Max() validators
  • Non-numeric limit query param returns 400, not a silently broken page
  • Non-numeric offset query param returns 400, not a silently broken page
  • E2E tests added and passing
  • PR description includes "Closes Fix pagination NaN bug in IntentsController.list() #64"

- Add ListIntentsDto with @ISINT()/@min()/@max() validators for limit and offset
- Move state/user/chain filters into the DTO as optional string fields
- Replace raw parseInt with DTO-backed validation, eliminating NaN silently corrupting pagination
- Add e2e tests asserting non-numeric limit/offset returns 400

Closes stellar-vortex-protocol#64
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Phantomcall Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix pagination NaN bug in IntentsController.list()

1 participant