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

feat: changing the shape of the output of the external api #439

Merged
merged 2 commits into from
Apr 25, 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
6 changes: 0 additions & 6 deletions backend-external/src/v1/routes/pay-transparency-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ const router = express.Router();
* Report:
* allOf:
* - $ref: "#/components/schemas/ReportItem"
* - type: object
* properties:
* history:
* type: array
* items:
* $ref: "#/components/schemas/ReportItem"
*
* PaginatedReports:
* type: object
Expand Down
1 change: 0 additions & 1 deletion backend/src/v1/routes/external-consumer-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ describe('external-consumer-routes', () => {
revision: REPORT.revision,
update_date: REPORT.update_date.toISOString(),
user_comment: REPORT.user_comment,
history: [],
},
],
totalRecords: 1,
Expand Down
83 changes: 43 additions & 40 deletions backend/src/v1/services/external-consumer-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,49 +143,52 @@ describe('external-consumer-service', () => {
revision: testData.revision,
update_date: testData.update_date,
user_comment: testData.user_comment,
history: [
});

expect(results.records[1]).toStrictEqual({
calculated_data: [
{
calculated_data: [
{
is_suppressed:
testData.report_history[0].calculated_data_history[0].is_suppressed,
value: testData.report_history[0].calculated_data_history[0].value,
calculation_code:
testData.report_history[0].calculated_data_history[0].calculation_code
.calculation_code,
},
],
company_address_line1:
testData.report_history[0].pay_transparency_company.address_line1,
company_address_line2:
testData.report_history[0].pay_transparency_company.address_line2,
company_bceid_business_guid:
testData.report_history[0].pay_transparency_company.bceid_business_guid,
company_city: testData.report_history[0].pay_transparency_company.city,
company_country: testData.report_history[0].pay_transparency_company.country,
company_id: testData.report_history[0].company_id,
company_name: testData.report_history[0].pay_transparency_company.company_name,
company_postal_code: testData.report_history[0].pay_transparency_company.postal_code,
company_province: testData.report_history[0].pay_transparency_company.province,
create_date: testData.report_history[0].create_date,
data_constraints: testData.report_history[0].data_constraints,
employee_count_range:
testData.report_history[0].employee_count_range.employee_count_range,
naics_code:
testData.report_history[0].naics_code_report_history_naics_codeTonaics_code
.naics_code,
naics_code_label:
testData.report_history[0].naics_code_report_history_naics_codeTonaics_code
.naics_label,
report_end_date: testData.report_history[0].report_end_date,
report_id: testData.report_history[0].report_id,
report_start_date: testData.report_history[0].report_start_date,
report_status: testData.report_history[0].report_status,
revision: testData.report_history[0].revision,
update_date: testData.report_history[0].update_date,
user_comment: testData.report_history[0].user_comment,
is_suppressed:
testData.report_history[0].calculated_data_history[0].is_suppressed,
value: testData.report_history[0].calculated_data_history[0].value,
calculation_code:
testData.report_history[0].calculated_data_history[0]
.calculation_code.calculation_code,
},
],
company_address_line1:
testData.report_history[0].pay_transparency_company.address_line1,
company_address_line2:
testData.report_history[0].pay_transparency_company.address_line2,
company_bceid_business_guid:
testData.report_history[0].pay_transparency_company.bceid_business_guid,
company_city: testData.report_history[0].pay_transparency_company.city,
company_country:
testData.report_history[0].pay_transparency_company.country,
company_id: testData.report_history[0].company_id,
company_name:
testData.report_history[0].pay_transparency_company.company_name,
company_postal_code:
testData.report_history[0].pay_transparency_company.postal_code,
company_province:
testData.report_history[0].pay_transparency_company.province,
create_date: testData.report_history[0].create_date,
data_constraints: testData.report_history[0].data_constraints,
employee_count_range:
testData.report_history[0].employee_count_range.employee_count_range,
naics_code:
testData.report_history[0]
.naics_code_report_history_naics_codeTonaics_code.naics_code,
naics_code_label:
testData.report_history[0]
.naics_code_report_history_naics_codeTonaics_code.naics_label,
report_end_date: testData.report_history[0].report_end_date,
report_id: testData.report_history[0].report_id,
report_start_date: testData.report_history[0].report_start_date,
report_status: testData.report_history[0].report_status,
revision: testData.report_history[0].revision,
update_date: testData.report_history[0].update_date,
user_comment: testData.report_history[0].user_comment,
});
});

Expand Down
39 changes: 26 additions & 13 deletions backend/src/v1/services/external-consumer-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import prismaReadOnlyReplica from '../prisma/prisma-client-readonly-replica';
import { LocalDate, convert } from '@js-joda/core';
import pick from 'lodash/pick';
import flatten from 'lodash/flatten';
import { PayTransparencyUserError } from './file-upload-service';

const denormalizeCompany = (company) => {
Expand All @@ -25,6 +26,7 @@ const denormalizeReport = (
calculation_code: any;
}[],
) => {

return {
...pick(report, [
'report_id',
Expand Down Expand Up @@ -143,6 +145,12 @@ const externalConsumerService = {
},
pay_transparency_company: true,
},
where: {
create_date: {
gte: convert(startDt).toDate(),
lte: convert(endDt).toDate(),
},
},
},
},
skip: offset,
Expand All @@ -153,22 +161,27 @@ const externalConsumerService = {
totalRecords: totalCount,
page: offset,
pageSize: limit,
records: results.map((report) => {
return {
...denormalizeReport(
report,
(r) => r.naics_code_pay_transparency_report_naics_codeTonaics_code,
(r) => r.pay_transparency_calculated_data,
),
history: report.report_history.map((report) => {
return denormalizeReport(
records: [
...results.map((report) => {
return {
...denormalizeReport(
report,
(r) =>
r.naics_code_pay_transparency_report_naics_codeTonaics_code,
(r) => r.pay_transparency_calculated_data,
),
};
}),
...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