Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Filter reports based on update date for external api #468

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions backend-external/src/v1/routes/pay-transparency-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ const router = express.Router();
* type: array
* items:
* $ref: "#/components/schemas/Report"
* history:
* type: array
* items:
* $ref: "#/components/schemas/Report"
*
*/

Expand All @@ -96,7 +100,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: []
Expand All @@ -118,13 +122,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:
Expand Down
1 change: 1 addition & 0 deletions backend/src/v1/routes/external-consumer-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('external-consumer-routes', () => {
expect(body).toEqual({
page: 0,
pageSize: 1000,
history: [],
records: [
{
calculated_data: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions backend/src/v1/services/external-consumer-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const externalConsumerService = {
.$replica()
.pay_transparency_report.findMany({
where: {
create_date: {
update_date: {
gte: convert(startDt).toDate(),
lte: convert(endDt).toDate(),
},
Expand All @@ -151,7 +151,7 @@ const externalConsumerService = {
pay_transparency_company: true,
},
where: {
create_date: {
update_date: {
gte: convert(startDt).toDate(),
lte: convert(endDt).toDate(),
},
Expand All @@ -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 {
Expand All @@ -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,
),
};
}),
],
};
},
Expand Down