I want to apply validation on request payload like, there is field name with string type. But name is not compulsory field but if it exist it must execute @IsNotEmpty()
I tried something like this
@IsNotEmpty() name?: string
// it not considering ?
optional constraint
You can use the @IsOptional()
validator:
Checks if given value is empty (
=== null
,=== undefined
) and if so, ignores all the validators on the property.