-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route link of the first page missing page param. #517
Comments
oh yea that's not right. What version are you using? |
Actually no that's fine. With no page param the default page is 1 |
Thanks for taking the time to review the issue. I received this error when querying: {
"statusCode": 400,
"message": "Validation failed (numeric string is expected)",
"error": "Bad Request"
} The following is not an excuse, just an explanation. Now that i review the error, it is easy to see the problem. @Get('paginated')
getPaginatedClients(
@Query('page', ParseIntPipe) page: number = 1,
@Query('limit', ParseIntPipe) limit: number = 10,
) {
limit = limit > 100 ? 100 : limit;
return this.clientSvc.getPaginatedClients({
page,
limit,
route: '/client/paginated',
});
} I am using the As not completely wasting your time, this issue can be converted to a suggestion:
Thanks. |
A much better suggestion would be to use the nestjs DefaultValuePipe. import { Controller, DefaultValuePipe, Get, ParseIntPipe, Query } from '@nestjs/common';
import { CatService } from './cat.service';
import { CatEntity } from './cat.entity';
import { Pagination } from 'nestjs-typeorm-paginate';
@Controller('cats')
export class CatsController {
constructor(private readonly catService: CatService) {}
@Get('')
async index(
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number = 1,
@Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit: number = 10,
): Promise<Pagination<CatEntity>> {
limit = limit > 100 ? 100 : limit;
return this.catService.paginate({
page,
limit,
route: 'http://cats.com/cats',
});
}
} |
Oh ok I see now, would you like to create a PR to add this to the docs? |
Sure. It is just a little correction to the readme. I will do it as soon as i can. |
The PR was open, so i will close this issue. |
I just tried the package. It looks very good.
But unfortunately, i just tested it and in the routes links, the "first" is not correct.
"first": "/client/paginated?limit=3",
The page parameter is missing.
Here is the received result a little more expanded.
I basically copy pasted the example of the readme file in a new nestjs project to test the package.
Here is the code that i used to try the package: sample-nestjs-typeorm-paginate
The text was updated successfully, but these errors were encountered: