Skip to content

Commit 68039cf

Browse files
committed
Revert "fix(orchestrator): remove default pagination on v2 endpoints (#1983)"
This reverts commit 5e30274.
1 parent bf518ef commit 68039cf

File tree

4 files changed

+37
-38
lines changed

4 files changed

+37
-38
lines changed

plugins/orchestrator-backend/src/service/api/v2.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ describe('getWorkflowOverview', () => {
126126
mapToWorkflowOverviewDTO(item),
127127
),
128128
paginationInfo: {
129-
offset: undefined,
130-
pageSize: undefined,
129+
page: 0,
130+
pageSize: 10,
131131
totalCount: mockOverviewsV1.items.length,
132132
},
133133
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
export const WORKFLOW_DATA_KEY = 'workflowdata';
22

33
export const INTERNAL_SERVER_ERROR_MESSAGE = 'internal server error';
4+
export const DEFAULT_PAGE_NUMBER = 0;
5+
export const DEFAULT_PAGE_SIZE = 10;
6+
export const DEFAULT_SORT_FIELD = undefined;
7+
export const DEFAULT_SORT_ORDER = 'ASC';
48
export const FETCH_PROCESS_INSTANCES_SORT_FIELD = 'start';

plugins/orchestrator-backend/src/types/pagination.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ describe('buildPagination()', () => {
55
const mockRequest: any = {
66
body: {},
77
};
8-
expect(buildPagination(mockRequest)).toEqual({});
8+
expect(buildPagination(mockRequest)).toEqual({
9+
limit: 10,
10+
offset: 0,
11+
order: 'ASC',
12+
sortField: undefined,
13+
});
914
});
1015
it('should build the correct pagination obj when partial query parameters are passed', () => {
1116
const mockRequest: any = {
@@ -16,9 +21,9 @@ describe('buildPagination()', () => {
1621
},
1722
};
1823
expect(buildPagination(mockRequest)).toEqual({
19-
limit: undefined,
20-
offset: undefined,
21-
order: undefined,
24+
limit: 10,
25+
offset: 0,
26+
order: 'ASC',
2227
sortField: 'lastUpdated',
2328
});
2429
});
@@ -50,9 +55,9 @@ describe('buildPagination()', () => {
5055
},
5156
};
5257
expect(buildPagination(mockRequest)).toEqual({
53-
limit: undefined,
54-
offset: undefined,
55-
order: undefined,
58+
limit: 10,
59+
offset: 0,
60+
order: 'ASC',
5661
sortField: undefined,
5762
});
5863
});
Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { Request } from 'express-serve-static-core';
22

3-
import { PaginationInfoDTO } from '@janus-idp/backstage-plugin-orchestrator-common';
3+
import {
4+
DEFAULT_PAGE_NUMBER,
5+
DEFAULT_PAGE_SIZE,
6+
DEFAULT_SORT_FIELD,
7+
DEFAULT_SORT_ORDER,
8+
} from '../service/constants';
49

510
export interface Pagination {
611
offset?: number;
@@ -10,33 +15,18 @@ export interface Pagination {
1015
}
1116

1217
export function buildPagination(req: Request): Pagination {
13-
const pagination: Pagination = {
14-
limit: undefined,
15-
offset: undefined,
16-
order: undefined,
17-
sortField: undefined,
18+
return {
19+
offset: isNaN(req.query.page as any)
20+
? DEFAULT_PAGE_NUMBER
21+
: Number(req.query.page),
22+
limit: isNaN(req.query.pageSize as any)
23+
? DEFAULT_PAGE_SIZE
24+
: Number(req.query.pageSize),
25+
sortField: req.query.orderBy
26+
? String(req.query.orderBy)
27+
: DEFAULT_SORT_FIELD,
28+
order: req.query.orderDirection
29+
? String(req.query.orderDirection)
30+
: DEFAULT_SORT_ORDER,
1831
};
19-
20-
if (!req.body?.paginationInfo) {
21-
return pagination;
22-
}
23-
const { offset, pageSize, orderBy, orderDirection } = req.body
24-
.paginationInfo as PaginationInfoDTO;
25-
26-
if (!isNaN(Number(offset))) {
27-
pagination.offset = Number(offset);
28-
}
29-
30-
if (!isNaN(Number(pageSize))) {
31-
pagination.limit = Number(pageSize);
32-
}
33-
34-
if (orderBy) {
35-
pagination.sortField = String(orderBy);
36-
}
37-
38-
if (orderDirection) {
39-
pagination.order = String(orderDirection).toUpperCase();
40-
}
41-
return pagination;
4232
}

0 commit comments

Comments
 (0)