Added additional endpoint to demonstrate pagination
This commit is contained in:
parent
0f01b0cb4e
commit
252efa3950
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue