Skip to content

Commit 09ef50b

Browse files
authored
Switch to client instead of server side pagination (#101)
Visual-Regression-Tracker/Visual-Regression-Tracker#213
1 parent 2c57aa2 commit 09ef50b

File tree

3 files changed

+11
-37
lines changed

3 files changed

+11
-37
lines changed

src/test-runs/test-runs.controller.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,19 @@ import { CommentDto } from '../shared/dto/comment.dto';
2121
import { TestRunResultDto } from './dto/testRunResult.dto';
2222
import { ApiGuard } from '../auth/guards/api.guard';
2323
import { CreateTestRequestDto } from './dto/create-test-request.dto';
24-
import { PaginatedTestRunDto } from './dto/testRun-paginated.dto';
24+
import { TestRunDto } from './dto/testRun.dto';
2525

2626
@ApiTags('test-runs')
2727
@Controller('test-runs')
2828
export class TestRunsController {
2929
constructor(private testRunsService: TestRunsService) {}
3030

3131
@Get()
32-
@ApiOkResponse({ type: PaginatedTestRunDto })
32+
@ApiOkResponse({ type: [TestRunDto] })
3333
@ApiBearerAuth()
3434
@UseGuards(JwtAuthGuard)
35-
get(
36-
@Query('buildId', new ParseUUIDPipe()) buildId: string,
37-
@Query('take', new ParseIntPipe()) take: number,
38-
@Query('skip', new ParseIntPipe()) skip: number
39-
): Promise<PaginatedTestRunDto> {
40-
return this.testRunsService.findMany(buildId, take, skip);
35+
get(@Query('buildId', new ParseUUIDPipe()) buildId: string): Promise<TestRunDto[]> {
36+
return this.testRunsService.findMany(buildId);
4137
}
4238

4339
@Get('recalculateDiff/:id')

src/test-runs/test-runs.service.spec.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -843,28 +843,16 @@ describe('TestRunsService', () => {
843843
merge: false,
844844
};
845845
const testRunFindManyMock = jest.fn().mockResolvedValueOnce([testRun]);
846-
const testRunCountMock = jest.fn().mockResolvedValueOnce(30);
847846
service = await initService({
848847
testRunFindManyMock,
849-
testRunCountMock,
850848
});
851849

852-
const result = await service.findMany(buildId, 10, 1);
850+
const result = await service.findMany(buildId);
853851

854852
expect(testRunFindManyMock).toHaveBeenCalledWith({
855853
where: { buildId },
856-
take: 10,
857-
skip: 1,
858-
});
859-
expect(testRunCountMock).toHaveBeenCalledWith({
860-
where: { buildId },
861-
});
862-
expect(result).toEqual({
863-
data: [new TestRunDto(testRun)],
864-
take: 10,
865-
skip: 1,
866-
total: 30,
867854
});
855+
expect(result).toEqual([new TestRunDto(testRun)]);
868856
});
869857

870858
it('delete', async () => {

src/test-runs/test-runs.service.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,11 @@ export class TestRunsService {
2828
private eventsGateway: EventsGateway
2929
) {}
3030

31-
async findMany(buildId: string, take: number, skip: number): Promise<PaginatedTestRunDto> {
32-
const [total, list] = await Promise.all([
33-
this.prismaService.testRun.count({ where: { buildId } }),
34-
this.prismaService.testRun.findMany({
35-
where: { buildId },
36-
take,
37-
skip,
38-
}),
39-
]);
40-
return {
41-
data: list.map((item) => new TestRunDto(item)),
42-
total,
43-
take,
44-
skip,
45-
};
31+
async findMany(buildId: string): Promise<TestRunDto[]> {
32+
const list = await this.prismaService.testRun.findMany({
33+
where: { buildId },
34+
});
35+
return list.map((item) => new TestRunDto(item));
4636
}
4737

4838
async findOne(

0 commit comments

Comments
 (0)