I have NestJS API, which has a PATCH endpoint for modifying a resource. I use the class-validator
library for validating the payload. In the DTO, all fields are set to optional with the @IsOptional()
decorator. Because of that, if I send an empty payload, the validation goes through and then the update operation errors.
I am wondering if there is a simple way to have all fields set to optional as I do and at the same time make sure that at least one of them is not empty, so the object is not empty.
Thanks!
I don't know if it is possible using DTO. For that purpose I use Pipes. Like this: