A Data Transfer Object (DTO) is a class whose class-validator decorators declare the accepted shape and constraints for data crossing an API boundary, enforced at runtime by Nest’s global ValidationPipe.
In simpler words
A DTO is the input checklist for an endpoint — decorators say what’s allowed, and the global pipe rejects anything that breaks the rules before your service runs.
Ground this in CreateTicketDto, UpdateTicketDto, and ListTicketsQueryDto, plus the global ValidationPipe options set in main.ts.
Add @Type when a query value needs to become a number
Declaring and enforcing the shape
Definition
The global ValidationPipe — configured with whitelist, forbidNonWhitelisted, and transform — validates every DTO-typed parameter, strips properties without validator decorators, rejects requests containing unknown properties, and converts primitive values to their declared types.
In simpler words
whitelist quietly drops extra fields; forbidNonWhitelisted turns those extra fields into a 400 instead of silently ignoring them; transform makes the DTO instance actually usable as typed data.
CreateTicketDto requires a non-empty, length-bound title and allows an optional description and status.
Every field a client may send needs a decorator — an undecorated field is invisible to whitelist and gets stripped even if the client sends it.
A missing title, an empty string, or a 6000-character description all fail validation before TicketsService.create runs.
Query strings need transform, not just validation
Definition
Query parameters arrive as strings, so a numeric or boolean DTO field needs an explicit transform such as @Type(() => Number) alongside its validator so the validated value has the correct runtime type.
In simpler words
IsInt alone would reject "20" as a string; @Type(() => Number) converts it to a number first, and then IsInt checks the number.
ListTicketsQueryDto applies this to page and limit, with @Min/@Max bounds that double as basic abuse protection on limit.
status and q stay plain strings, validated with @IsEnum and @IsString respectively.