I'm trying to create a PaginationDTO for using all across my app, and it behaves perfectly in all my controller methods except one.
Below endpoint is the one that throws error
Validation failed (numeric string is expected)
@Get('bannedUsers')
@ApiOperation({summary: "Banlanan kullanıcıların listesini getirir"})
@Tags([PermissionTypes.USER_OPERATIONS, RoleRequestTypes.SERVICE])
@UseGuards(AuthGuard, RoleGuard)
async getBannedUsers(@Query() paginationDTO: PaginationDTO,) {
return this.accountMicroservice.sendMicroserviceRequest("get-banned-users", paginationDTO)
}
And this endpoint just works perfectly
@Get('following/:id')
@ApiOperation({summary: "Sicili girilen kullanıcının takip ettiklerini getirir"})
@ApiParam({name: "id", description: "Takipçileri istenen kullanıcının sicili"})
@Tags([PermissionTypes.DEFAULT, RoleRequestTypes.SERVICE, Utilities.ME])
@UseGuards(AuthGuard, RoleGuard)
async getUserFollowing(@Query() paginationDTO: PaginationDTO, @Param('id', ParseIntPipe) id: number): Promise<any> {
const paginationDtoWithId: PaginationWithIdDTO = <PaginationWithIdDTO>{
...paginationDTO,
id: id
}
return this.accountMicroservice.sendMicroserviceRequest("get-user-following", paginationDtoWithId)
}
Difference between these two is @Param and also when i add @Param to endpoint above, it also works?
Here's my pagination DTO below
PaginationDTO
import {ApiProperty} from "@nestjs/swagger";
import {Transform} from "class-transformer";
export class PaginationDTO {
@ApiProperty({type: () => Number})
@Transform(({value}) => {
const parsedValue = Number.parseInt(value);
console.log("parsed: " + parsedValue)
console.log(value);
return !isNaN(parsedValue) ? parsedValue : 0;//new UnprocessableEntityException();
})
page: Number;
@ApiProperty({type: () => Number})
@Transform(({value}) => {
const parsedValue = Number.parseInt(value);
console.log("parsed: " + parsedValue)
console.log(value);
return !isNaN(parsedValue) ? parsedValue : 15;
})
limit: Number;
}
My application uses global validation pipe with transform option set to true. I can provide further info if needed. Thanks in advance.