Validate body with class validator!
Install peer dependencies.
npm i reflect-metadata class-validator class-transformer-validator class-transformer
Replace @reqBody()
with @validatedBody()
.
import { validatedBody } from 'tachijs-validated-body'
class MessageRequestBodyDTO {
@IsString()
message: string
}
@controller('/')
class EchoController {
@httpPost('/')
// echo(@reqBody() body: unknown) {
echo(@validatedBody() body: MessageRequestBodyDTO) {
return body.message
}
}
MIT © Junyoung Choi