paginate wagons, locomotives and routes lists server-side

This commit is contained in:
Marshal
2026-07-27 21:27:36 +00:00
parent 496c66017f
commit 481878e553
7 changed files with 49 additions and 44 deletions

View File

@@ -72,16 +72,7 @@ export class ListWagonsQueryDto {
@Min(1)
page?: number;
@ApiPropertyOptional({ minimum: 1, maximum: 500 })
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(500)
limit?: number;
/** Page size for `GET /wagons/paged`; the legacy `limit` still drives `GET /wagons`. */
@ApiPropertyOptional({ default: 20, minimum: 1, maximum: 100 })
@ApiPropertyOptional({ default: 10, minimum: 1, maximum: 100 })
@IsOptional()
@Type(() => Number)
@IsInt()

View File

@@ -39,19 +39,13 @@ export class WagonsController {
@Get()
@StaffReference()
@ApiOperation({ summary: 'List all wagons' })
@ApiOperation({
summary: 'List wagons, paginated ({items, meta}) — 10 per page by default',
})
findAll(@Query() query: ListWagonsQueryDto) {
return this.wagonsService.findAll(query);
}
// Must be declared before @Get(':id') so the path isn't captured as an id.
@Get('paged')
@StaffReference()
@ApiOperation({ summary: 'List wagons, paginated ({items, meta})' })
findAllPaged(@Query() query: ListWagonsQueryDto) {
return this.wagonsService.findAllPaged(query);
}
@Get(':id')
@StaffReference()
@ApiOperation({ summary: 'Get a wagon by ID' })

View File

@@ -115,20 +115,13 @@ export class WagonsService {
return qb;
}
async findAll(query: ListWagonsQueryDto = {}): Promise<Wagon[]> {
const qb = this.buildListQuery(query);
if (query.page && query.limit) {
qb.skip((Number(query.page) - 1) * Number(query.limit));
}
if (query.limit) qb.take(Number(query.limit));
return qb.getMany();
}
/** Same filters as `findAll`, on the shared `{items, meta}` list envelope. */
findAllPaged(query: ListWagonsQueryDto = {}): Promise<PaginatedResponse<Wagon>> {
return paginateQuery(this.buildListQuery(query), query);
/**
* The wagon list is always a page. Callers that genuinely need every row
* (yard workspace, coupling pickers) walk the pages client-side — see
* `wagonService.listAll` in the backoffice.
*/
findAll(query: ListWagonsQueryDto = {}): Promise<PaginatedResponse<Wagon>> {
return paginateQuery(this.buildListQuery(query), query, { defaultPageSize: 10 });
}
async findById(id: string): Promise<Wagon> {