Skip to content

Commit

Permalink
Fix pagination for plays and rounds resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodymyr-Kuchinskyi committed Jun 18, 2024
1 parent 9525f4f commit 851b677
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions server/src/repository/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ export class PlayRepository {
const subQuery = qb.subQuery().select('max(round_id)').from(Play, 'maxp').getQuery();
return 'round_id = ' + subQuery;
})
.limit(pagination.limit)
.offset(pagination.offset)
.orderBy('timestamp', 'DESC');

if (pagination.limit !== -1) {
queryBuilder.limit(pagination.limit).offset(pagination.offset);
}

return queryBuilder.getManyAndCount();
}

Expand Down
7 changes: 5 additions & 2 deletions server/src/repository/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ export class RoundRepository {

async getPaginatedRounds(pagination: { limit: number; offset: number }, params: { isFinished: boolean } = { isFinished: false }): Promise<[Round[], number]> {
const options: FindManyOptions<Round> = {
take: pagination.limit,
skip: pagination.offset,
order: {
roundId: 'DESC',
},
};

if (pagination.limit !== -1) {
options.take = pagination.limit;
options.skip = pagination.offset;
}

if (params.isFinished) {
options.where = { isFinished: true };
}
Expand Down

0 comments on commit 851b677

Please sign in to comment.