I am working with NestJS and class-validator to validate an array of objects in the following format:
[
{gameId: 1, numbers: [1, 2, 3, 5, 6]},
{gameId: 2, numbers: [5, 6, 3, 5, 8]}
]
This is my resolver function:
createBet(@Args('createBetInput') createBetInput: CreateBetInput) {
return this.betsService.create(createBetInput);
}
Here is my CreateBetInput DTO:
import { InputType, Field, Int } from '@nestjs/graphql';
import { IsArray, IsNumber } from 'class-validator';
@InputType()
export class CreateBetInput {
@IsNumber()
@Field(() => Int)
gameId: number;
@Field(() => [Int])
@IsArray()
numbers: number[];
}
I have attempted different solutions without success. I am unsure how to proceed further.
Any suggestions on modifying the DTO for proper validation?