From 4118637010f43b5b3c0b632b5370695b8fba5b81 Mon Sep 17 00:00:00 2001 From: goemen Date: Thu, 9 May 2024 10:11:49 -0700 Subject: [PATCH 1/3] Filter reports based on update date for external api --- backend-external/src/v1/routes/pay-transparency-routes.ts | 6 +++--- backend/src/v1/services/external-consumer-service.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend-external/src/v1/routes/pay-transparency-routes.ts b/backend-external/src/v1/routes/pay-transparency-routes.ts index d4ddd61e2..25eb9d7b4 100644 --- a/backend-external/src/v1/routes/pay-transparency-routes.ts +++ b/backend-external/src/v1/routes/pay-transparency-routes.ts @@ -96,7 +96,7 @@ const router = express.Router(); * name: Reports * /: * get: - * summary: Get published reports within a date range (date range defaults to the last 30 days) + * summary: Get published reports with update date within a date range (date range defaults to the last 30 days) * tags: [Reports] * security: * - ApiKeyAuth: [] @@ -118,13 +118,13 @@ const router = express.Router(); * type: date * pattern: /([0-9]{4})-(?:[0-9]{2})-([0-9]{2})/ * required: false - * description: "Start date for the date range filter (format: YYYY-MM-dd) - optional" + * description: "Start date for the update date range filter (format: YYYY-MM-dd) - optional" * - in: query * name: endDate * type: string * pattern: /([0-9]{4})-(?:[0-9]{2})-([0-9]{2})/ * required: false - * description: "End date for the date range filter (format: YYYY-MM-dd) - optional" + * description: "End date for the update date range filter (format: YYYY-MM-dd) - optional" * * * responses: diff --git a/backend/src/v1/services/external-consumer-service.ts b/backend/src/v1/services/external-consumer-service.ts index 41fcf7fb2..14033dab9 100644 --- a/backend/src/v1/services/external-consumer-service.ts +++ b/backend/src/v1/services/external-consumer-service.ts @@ -124,7 +124,7 @@ const externalConsumerService = { .$replica() .pay_transparency_report.findMany({ where: { - create_date: { + update_date: { gte: convert(startDt).toDate(), lte: convert(endDt).toDate(), }, From 9ac6967b66355d11c641da1282a4b115338e3a38 Mon Sep 17 00:00:00 2001 From: goemen Date: Thu, 9 May 2024 11:42:02 -0700 Subject: [PATCH 2/3] filter history based on update_date --- backend/src/v1/services/external-consumer-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/v1/services/external-consumer-service.ts b/backend/src/v1/services/external-consumer-service.ts index 14033dab9..b068712d3 100644 --- a/backend/src/v1/services/external-consumer-service.ts +++ b/backend/src/v1/services/external-consumer-service.ts @@ -151,7 +151,7 @@ const externalConsumerService = { pay_transparency_company: true, }, where: { - create_date: { + update_date: { gte: convert(startDt).toDate(), lte: convert(endDt).toDate(), }, From 5584cc6c045598260541be2252f519574e3fca9d Mon Sep 17 00:00:00 2001 From: goemen Date: Thu, 9 May 2024 12:28:21 -0700 Subject: [PATCH 3/3] add history attribute to the get reports external api --- .../src/v1/routes/pay-transparency-routes.ts | 4 ++++ .../v1/routes/external-consumer-routes.spec.ts | 1 + .../services/external-consumer-service.spec.ts | 2 +- .../v1/services/external-consumer-service.ts | 18 +++++++++--------- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/backend-external/src/v1/routes/pay-transparency-routes.ts b/backend-external/src/v1/routes/pay-transparency-routes.ts index 25eb9d7b4..59c12863f 100644 --- a/backend-external/src/v1/routes/pay-transparency-routes.ts +++ b/backend-external/src/v1/routes/pay-transparency-routes.ts @@ -87,6 +87,10 @@ const router = express.Router(); * type: array * items: * $ref: "#/components/schemas/Report" + * history: + * type: array + * items: + * $ref: "#/components/schemas/Report" * */ diff --git a/backend/src/v1/routes/external-consumer-routes.spec.ts b/backend/src/v1/routes/external-consumer-routes.spec.ts index 873d3d922..6e91033a8 100644 --- a/backend/src/v1/routes/external-consumer-routes.spec.ts +++ b/backend/src/v1/routes/external-consumer-routes.spec.ts @@ -79,6 +79,7 @@ describe('external-consumer-routes', () => { expect(body).toEqual({ page: 0, pageSize: 1000, + history: [], records: [ { calculated_data: [ diff --git a/backend/src/v1/services/external-consumer-service.spec.ts b/backend/src/v1/services/external-consumer-service.spec.ts index 47a1b69bd..d8fb00a86 100644 --- a/backend/src/v1/services/external-consumer-service.spec.ts +++ b/backend/src/v1/services/external-consumer-service.spec.ts @@ -144,7 +144,7 @@ describe('external-consumer-service', () => { user_comment: testData.user_comment, }); - expect(results.records[1]).toStrictEqual({ + expect(results.history[0]).toStrictEqual({ calculated_data: [ { is_suppressed: diff --git a/backend/src/v1/services/external-consumer-service.ts b/backend/src/v1/services/external-consumer-service.ts index b068712d3..6ca276624 100644 --- a/backend/src/v1/services/external-consumer-service.ts +++ b/backend/src/v1/services/external-consumer-service.ts @@ -165,6 +165,15 @@ const externalConsumerService = { return { page: offset, pageSize: limit, + history: flatten(results.map((r) => r.report_history)).map((report) => { + return { + ...denormalizeReport( + report, + (r) => r.naics_code_report_history_naics_codeTonaics_code, + (r) => r.calculated_data_history, + ), + }; + }), records: [ ...results.map((report) => { return { @@ -176,15 +185,6 @@ const externalConsumerService = { ), }; }), - ...flatten(results.map((r) => r.report_history)).map((report) => { - return { - ...denormalizeReport( - report, - (r) => r.naics_code_report_history_naics_codeTonaics_code, - (r) => r.calculated_data_history, - ), - }; - }), ], }; },