Skip to content

Commit

Permalink
fix: reduce the default and maximum page size for the data returned (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
goemen committed May 13, 2024
1 parent b8acf41 commit e1122f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 9 additions & 11 deletions backend-external/src/v1/routes/pay-transparency-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ const router = express.Router();
* type: array
* items:
* $ref: "#/components/schemas/Report"
* history:
* type: array
* items:
* $ref: "#/components/schemas/Report"
*
*/

/**
Expand All @@ -109,14 +104,17 @@ const router = express.Router();
* name: page
* schema:
* type: integer
* minimum: 0
* required: false
* description: The page offset number to retrive reports - optional
* - in: query
* name: pageSize
* schema:
* type: integer
* minimum: 1
* maximum: 50
* required: false
* description: The number of records/reports per page (max 1000) - optional
* description: The number of records/reports per page (max 50, default 50) - optional
* - in: query
* name: startDate
* type: date
Expand Down Expand Up @@ -147,17 +145,17 @@ router.get(
try {
const startDate = req.query.startDate?.toString();
const endDate = req.query.endDate?.toString();
const offset = Number((req.query.page || '0')?.toString());
const limit = Number((req.query.pageSize || '1000')?.toString());
if (isNaN(offset) || isNaN(limit)) {
const page = Number((req.query.page || '0')?.toString());
const pageSize = Number((req.query.pageSize || '50')?.toString());
if (isNaN(page) || isNaN(pageSize)) {
return res.status(400).json({ error: 'Invalid offset or limit' });
}
const { status, data } =
await payTransparencyService.getPayTransparencyData(
startDate,
endDate,
offset,
limit,
page * pageSize,
pageSize,
);

if (data.error) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/v1/routes/external-consumer-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('external-consumer-routes', () => {
.expect(({ body }) => {
expect(body).toEqual({
page: 0,
pageSize: 1000,
pageSize: 50,
records: [
{
calculated_data: [
Expand Down
6 changes: 4 additions & 2 deletions backend/src/v1/services/external-consumer-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const buildReport = (data: RawQueryResult[]) => {
};
};

const DEFAULT_PAGE_SIZE = 50;

const externalConsumerService = {
/**
* This function returns a list of objects with pagination details to support the analytics team.
Expand Down Expand Up @@ -113,8 +115,8 @@ const externalConsumerService = {
.plusDays(1)
.withHour(0)
.withMinute(0);
if (limit > 1000 || !limit || limit <= 0) {
limit = 1000;
if (!limit || limit <= 0 || limit > DEFAULT_PAGE_SIZE) {
limit = DEFAULT_PAGE_SIZE;
}
if (!offset || offset < 0) {
offset = 0;
Expand Down

0 comments on commit e1122f7

Please sign in to comment.