-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add request body validation with DTOs & Swagger docs to the routes #96
base: develop
Are you sure you want to change the base?
feat: Add request body validation with DTOs & Swagger docs to the routes #96
Conversation
@IsNumber() | ||
@Min(1) | ||
@Transform((value) => Number(value.value)) | ||
readonly quantity?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
não deveria ser obrigatório? afinal estou criando um suprimento e estou dizendo que seu deve ser mínimo um
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu apenas segui a lógica já implementada na aplicação, então nesse DTO a propriedade "quantity" deve ser opcional, como consta nos types
backend/src/shelter-supply/types.ts
Lines 5 to 25 in c40e724
const ShelterSupplySchema = z.object({ | |
id: z.string(), | |
shelterId: z.string(), | |
supplyId: z.string(), | |
priority: z.union([ | |
z.literal(SupplyPriority.UnderControl), | |
z.literal(SupplyPriority.Remaining), | |
z.literal(SupplyPriority.Needing), | |
z.literal(SupplyPriority.Urgent), | |
]), | |
quantity: z.number().gt(0).nullable().optional(), | |
createdAt: z.string(), | |
updatedAt: z.string().nullable().optional(), | |
}); | |
const CreateShelterSupplySchema = ShelterSupplySchema.pick({ | |
shelterId: true, | |
supplyId: true, | |
priority: true, | |
quantity: true, | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfeito! Acredito que não era para ter esse 'estado' nos types mas como já é o formato antigo, tudo em ordem camarada
d6e5d62
to
3e68056
Compare
Essse PR adiciona a validação do corpo das requisições nas rotas, garantindo que apenas os dados solicitados pela aplicação sejam aceitos, com a tipagem correta. Foi utilizado as bibliotecas:
Essa validação ocorre antes do processamento dos dados pela aplicação, então só serão processados se todos os campos estiverem válidos.
Sem validação (ANTES):
Imagens
Com validação (DEPOIS):
Imagens