Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1stack specificStack: node
validationdtoerror-handlingdry
Validate structured input through a DTO + validate() rather than manual field checks
Replace hand-written field-by-field validation with a class-validator DTO and an error transformer that lists invalid fields automatically.
PR: vinify-backend · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | if (!body.name) errors.push('name'); |
| 2 | if (!body.email) errors.push('email'); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const dto = plainToInstance(CreateDto, body); |
| 2 | const errors = await validate(dto); |
| 3 | return transformValidationErrors(errors); |
Explanation (EN)
Objašnjenje (HR)