我使用 validateIf() 来检查 paymentService 是否等于我的代码中定义的某个枚举值。但它不会验证并抛出错误。
@ApiProperty({ required: true })
@IsNotEmpty()
@IsEnum(PAYMENT_SERVICE,{
message:`Payment Service must be one of the valid values ${Object.values(PAYMENT_SERVICE)}`
})
paymentService: PAYMENT_SERVICE
@ApiProperty({ required: true })
@IsNotEmpty()
@IsInt()
@Transform(({ value }) => parseInt(value))
amount: number
@ApiProperty({ required: false })
@ValidateIf((object) => object.paymentService == PAYMENT_SERVICE.STRIPE)
@IsString()
@IsOptional()
currency: string
@ApiProperty({ required: true })
@IsNotEmpty()
@IsInt()
@Transform(({ value }) => parseInt(value))
qurandaziId: number
}
export enum PAYMENT_SERVICE {
STRIPE = 'STRIPE',
JAZZCASH = 'JAZZCASH',
}
in currency field replace @IsOptional() to @IsNotEmpty({ message: 'currency_not_empty' })