Using class-validator along with NestJS I want to validate that a user provides either propertyA or a propertyB but they don't need to provide both.
Currently, I'm doing something like:
export class TestDto {
@ValidateIf(obj => !obj.propertyB)
@IsString()
@IsNotEmpty()
propertyA
@ValidateIf(obj => !obj.propertyA)
@IsString()
@IsNotEmpty()
propertyB
}
If they provide none of the parameters there will be multiple errors saying that propertyA and propertyB are required and should be strings etc.
In the case that they provide neither property, I would want only a single error saying something like: "You must provide propertyA or propertyB."
Can this be accomplished using NestJS/class-validator?