Skip to content
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

[Issue]: Offset pagination - Offset skips first entity #432

Closed
chihabhajji opened this issue Jan 29, 2024 · 8 comments
Closed

[Issue]: Offset pagination - Offset skips first entity #432

chihabhajji opened this issue Jan 29, 2024 · 8 comments
Assignees

Comments

@chihabhajji
Copy link

Hello,

when using offset pagination it skips the first record in the database.

possible fixes are either allowing the offset to be 0 or using offset -1

@jiho-kr
Copy link
Contributor

jiho-kr commented Jan 29, 2024

Hi @chihabhajji

I tried to check it through unit-test(#433), but I couldn't reproduce it.

Can you give me more information?

@chihabhajji
Copy link
Author

chihabhajji commented Jan 31, 2024

Hello @jiho-kr , gladly, here is my database, it has one record for the purpose of this test
image
when i try the endpoint with 10 limit and offset 1 i get the following
image
image
the metadata has total 1 but the record is not returned.
and after i add a user and run the same query i get the following
image
this is my controller
typescript @ApiTags('users') @ApiBearerAuth() @ApiOAuth2(['email', 'profile']) @Crud({ entity: User, routes: { readMany: { relations: ['profile'], paginationType: 'offset', numberOfTake: 10, softDelete: false, sort: 'ASC', swagger: { response: DepopulatedUserInfoDTO, }, decorators: [ApiQuery({ name: 'role', type: String, enum: ERole })], exclude: ['password', '_id', 'deletedAt'], }, readOne: { exclude: ['password'], relations: ['profile', 'organizations', 'memberOrganizations'], swagger: { response: OmitType(User, ['password', 'deletedAt']), }, }, search: { relations: ['profile'], paginationType: 'offset', numberOfTake: 10, swagger: { response: DepopulatedUserInfoDTO, }, exclude: ['password', '_id', 'deletedAt'], }, }, only: [Method.READ_MANY, Method.READ_ONE, Method.UPDATE, Method.SEARCH], }) @Controller('users') export class UsersController { // noinspection JSUnusedLocalSymbols constructor(private readonly crudService: UsersService) {} }

@jiho-kr
Copy link
Contributor

jiho-kr commented Feb 2, 2024

Hi, @chihabhajji

Because you set the offset to 1, the data is searched from the second time.
You should either not set offset or use 0.

This article might be helpful for you.

@chihabhajji
Copy link
Author

Yes i am aware of that, thats why my issue title says allow offset to be 0, because 0 is not accepted

@jiho-kr
Copy link
Contributor

jiho-kr commented Feb 2, 2024

aha I get it, i'll check 0 is not accepted

@chihabhajji
Copy link
Author

image

@jiho-kr
Copy link
Contributor

jiho-kr commented Feb 5, 2024

https://github.com/woowabros/nestjs-library-crud/releases/tag/0.10.2

@jiho-kr jiho-kr closed this as completed Feb 5, 2024
@jiho-kr jiho-kr self-assigned this Feb 5, 2024
@chihabhajji
Copy link
Author

thank you ^^

@jiho-kr jiho-kr mentioned this issue Feb 8, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants