Added additional endpoint to demonstrate pagination

This commit is contained in:
GeorgeWebberley 2026-03-01 12:48:17 +01:00
parent 0f01b0cb4e
commit 252efa3950
2 changed files with 20 additions and 0 deletions

View file

@ -49,4 +49,14 @@ export class CasesResolver {
return this.casesService.processAndSave(buffer, mimetype, filename);
}
// An additional simple fetch all endpoint to demonstrate pagination
@Query(() => [CaseLaw], { name: 'caseLaws' })
async findAll(
@Args('status', { type: () => CaseStatus, nullable: true }) status?: CaseStatus,
@Args('take', { type: () => Int, nullable: true, defaultValue: 20 }) take?: number,
@Args('skip', { type: () => Int, nullable: true, defaultValue: 0 }) skip?: number,
) {
return this.casesService.findAll(status, take, skip);
}
}

View file

@ -58,4 +58,14 @@ export class CasesService {
if (!caseLaw) throw new NotFoundException('Case not found');
return caseLaw;
}
async findAll(status?: CaseStatus, take = 20, skip = 0) {
return this.prisma.caseLaw.findMany({
where: status ? { status } : undefined,
orderBy: { createdAt: 'desc' },
take: Math.min(take, 100),
skip,
});
}
}