I have the following DTO
export class UpsertSubscription {
@Expose()
@ValidateIf((o) => !o.monthly && !o.yearly)
@IsNumber({}, { message: 'tiers.priceMustBeANumber' })
@Min(0, { message: 'tiers.priceMustBeAtLeastZero' })
public daily?: number;
@Expose()
@ValidateIf((o) => !o.daily && !o.yearly)
@IsNumber({}, { message: 'tiers.priceMustBeANumber' })
@Min(0, { message: 'tiers.priceMustBeAtLeastZero' })
public monthly?: number;
@Expose()
@ValidateIf((o) => !o.daily && !o.monthly)
@IsNumber({}, { message: 'tiers.priceMustBeANumber' })
@Min(0, { message: 'tiers.priceMustBeAtLeastZero' })
public yearly?: number;
}
the ValidateIf decorator is supposed to make the property optional in case one of the other two is defined. However, if let’s say daily is 10, which is valid, monthly can be set to any value, like “something different”, which is not fine.
Is there a way to make the properties optional if one is defined?