I have a DTO in which I have a field which is an array of numbers. These ids are coming via API query parameters. I am using Class Transformer to transform these ids into an array of numbers. But I am getting an array of strings only. My DTO class is as below.
export class EvseGetQueryDto {
...
...
@IsOptional()
@IsArray()
@IsNumber({}, {each: true})
@ApiProperty({ type: [Number] })
@Type(() => Number)
locations?: number[];
...
...
}
My Controller code looks like this.
async GetAll(@Query() query: EvseGetQueryDto): Promise<EvseDto[]> {
return await this.evseService.GetAll(query);
}
If I call my controller like this below, I am still getting ['1', '2'] in my locations field.
http://localhost:3000/evses?locations[]=1&locations[]=2
Can anyone please guide me?