Skip to content

Commit 02f9562

Browse files
author
Roman Snapko
committed
Fix pagination logic to always fill the first page
1 parent ca3ea6c commit 02f9562

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

packages/server/api/src/app/helper/pagination/paginator.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,22 @@ export default class Paginator<Entity extends ObjectLiteral> {
9191
public async paginate(
9292
builder: SelectQueryBuilder<Entity>,
9393
): Promise<PagingResult<Entity>> {
94-
const entities = await this.appendPagingQuery(builder).getMany();
95-
const hasMore = entities.length > this.limit;
94+
let entities = await this.appendPagingQuery(builder).getMany();
95+
let hasMore = entities.length > this.limit;
96+
97+
if (
98+
this.hasBeforeCursor() &&
99+
!this.hasAfterCursor() &&
100+
entities.length < this.limit
101+
) {
102+
this.afterCursor = null;
103+
this.beforeCursor = null;
104+
this.nextAfterCursor = null;
105+
this.nextBeforeCursor = null;
106+
107+
entities = await this.appendPagingQuery(builder).getMany();
108+
hasMore = entities.length > this.limit;
109+
}
96110

97111
if (hasMore) {
98112
entities.splice(entities.length - 1, 1);

0 commit comments

Comments
 (0)