backend icon indicating copy to clipboard operation
backend copied to clipboard

Reject invalid `completed` query values instead of reading them as `false`

Open AlexSergey opened this issue 2 weeks ago • 2 comments

What is wrong

src/api/todos/dtos/queries/todos-query.dto.ts (line 12) transforms the filter with value === 'true' || value === true. Any other value (completed=yes, completed=1, completed=) becomes false, @IsBoolean() passes, and GET /api/v1/todos silently returns only unfinished todos. The request body already rejects completed: 'yes' with 422 (test/todos.e2e-spec.ts), and docs/architecture/api.md documents only true/false for the query.

Why it matters

A typo in a filter returns wrong data instead of a validation error.

Definition of done

  • 'true' maps to true, 'false' to false; any other value is passed through unchanged so @IsBoolean() rejects it with 422 DTO_VALIDATION_ERROR.
  • A new todos-query.dto.spec.ts covers invalid values first, then true/false/absent (see src/api/client-logs/dtos/web-log.dto.spec.ts for the pattern); npx jest src/api/todos/dtos passes.
  • Optional: a GET ?completed=yes → 422 case in test/todos.e2e-spec.ts.

Pointers

Error handling.

AlexSergey avatar Nov 15 '26 11:11 AlexSergey

Hi! I'd like to work on this one if it's still free.

My plan, following the definition of done: map only 'true' and 'false' in the transform and pass any other value through unchanged, so @IsBoolean() rejects it with a 422, and add e2e cases for completed=yes, completed=1 and an empty value.

devmaiter avatar Nov 15 '26 12:11 devmaiter

@devmaiter , Thanks, the plan looks right, it's yours! One addition: the unit spec src/api/todos/dtos/queries/todos-query.dto.spec.ts is required by the definition of done. Follow the pattern in src/api/client-logs/dtos/web-log.dto.spec.ts: invalid values first (yes, 1, empty), then true/false/absent, and npx jest src/api/todos/dtos should pass. The e2e cases are welcome but optional, since they need Postgres and Redis running locally. If that's a hassle, the unit spec alone is enough.

AlexSergey avatar Nov 15 '26 12:11 AlexSergey