How to make param required in NestJS?
Use class-validator
. Pipes are definitely made for that !
Example : create-user.dto.ts
import { IsNotEmpty } from 'class-validator';
export class CreateUserDto {
@IsNotEmpty()
password: string;
}
For more information see class-validator
documentation :
https://github.com/typestack/class-validator
And NestJS Pipes & Validation documentation : https://docs.nestjs.com/pipes https://docs.nestjs.com/techniques/validation
There hava a easy way to valide you parameter, https://docs.nestjs.com/techniques/validation