I have a object it type is product:{[key:string]:[{min:number,max:number,discount:number}]}
that product if {} return error or min or max or discount not exist return error Or the type of one is not number return error in class-validator nestjs
simple data:
"products": {
"MciTopup": [ { "min": 4100 , "max": 1000, "discount": 2 } ],
"AtiTickets": [ { "min": 40000, "max": 2000, "discount": 6 } ]
}
my code but it don’t work
export class ProductItemDto {
@IsNumber()
max!: number;
@IsNumber()
@Min(0)
@Max(100)
discount!: number;
@IsNumber()
min!: number; // Make min property optional
}
export class CreateCampaignDto {
@ValidateNested({ each: true })
@Type(() => ProductItemDto)
products!: { [key: string]: ProductItemDto[] };
i tried to write this code but it do not work if you send empty {} it work or it error for keys that is string