Skip to content

Commit

Permalink
fix: afs needs to be paginating (#3955)
Browse files Browse the repository at this point in the history
  • Loading branch information
YazeedLoonat authored Mar 15, 2024
1 parent 5801e31 commit 02a4dbd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion api/src/services/application-flagged-set.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import { AfsQueryParams } from '../dtos/application-flagged-sets/afs-query-param
import { AfsMeta } from '../dtos/application-flagged-sets/afs-meta.dto';
import { OrderByEnum } from '../enums/shared/order-by-enum';
import { View } from '../enums/application-flagged-sets/view';
import { buildPaginationMetaInfo } from '../utilities/pagination-helpers';
import {
buildPaginationMetaInfo,
calculateSkip,
calculateTake,
} from '../utilities/pagination-helpers';
import { AfsResolve } from '../dtos/application-flagged-sets/afs-resolve.dto';
import { User } from '../dtos/users/user.dto';
import { Application } from '../dtos/applications/application.dto';
Expand Down Expand Up @@ -67,6 +71,15 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
where: whereClause,
});

// if passed in page and limit would result in no results because there aren't that many listings
// revert back to the first page
let page = params.page;
if (count && params.limit && params.limit !== 'all' && params.page > 1) {
if (Math.ceil(count / params.limit) < params.page) {
page = 1;
}
}

const rawAfs = await this.prisma.applicationFlaggedSet.findMany({
include: {
listings: true,
Expand All @@ -80,6 +93,8 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
orderBy: {
id: OrderByEnum.DESC,
},
skip: calculateSkip(params.limit, page),
take: calculateTake(params.limit),
});

const totalFlagged = await this.prisma.applicationFlaggedSet.count({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ describe('Testing application flagged set service', () => {
orderBy: {
id: OrderByEnum.DESC,
},
skip: 0,
});

expect(prisma.applicationFlaggedSet.count).toHaveBeenNthCalledWith(1, {
Expand Down

0 comments on commit 02a4dbd

Please sign in to comment.