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(backend-external): duplicate results in api #486

Merged
merged 4 commits into from
May 15, 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
9 changes: 5 additions & 4 deletions backend/src/v1/services/external-consumer-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ const externalConsumerService = {

/**
* 1) Create a union of the pay_transparency_report and report_history table as reports
* 2) Create a union of the pay_transparency_calculated_data and calculated_data_history as calculated
* 3) Paginate the reports
* 4) Join reports and calculated_data based on report_change_id
* 2) Sort by update date, then by revision (have to sort by revision too because reports in version PT1.2 all share the same update date )
* 3) Create a union of the pay_transparency_calculated_data and calculated_data_history as calculated
* 4) Paginate the reports
* 5) Join reports and calculated_data based on report_change_id
*/
const getReportsQuery = Prisma.sql`select *
from ((select report.report_id,
Expand Down Expand Up @@ -229,7 +230,7 @@ const externalConsumerService = {
where report_status = 'Published'
and (report.update_date >= ${convert(startDt).toDate()}
and report.update_date < ${convert(endDt).toDate()})))
order by update_date
order by update_date, revision
offset ${offset}
limit ${limit}) as reports

Expand Down
11 changes: 10 additions & 1 deletion backend/src/v1/services/report-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
LocalDate,
LocalDateTime,
TemporalAdjusters,
ZoneId,
convert,
Expand Down Expand Up @@ -379,6 +380,14 @@ const reportServicePrivate = {
return `$${amountDollars.toFixed(2)}`;
},

/**
* Copies the report and calculated data to the history table.
* Copies the report to the report history with a report_history_id.
* Copies the calculated data to the history associated with a report_history_id.
* Removes the calculated data.
* @param tx
* @param report - The entire report which should be moved
*/
async movePublishedReportToHistory(tx, report: pay_transparency_report) {
if (report.report_status != enumReportStatus.Published) {
throw new Error(
Expand Down Expand Up @@ -1271,7 +1280,7 @@ const reportService = {
user_comment: full_report_to_publish.user_comment,
data_constraints: full_report_to_publish.data_constraints,
revision: parseInt(existing_published_report.revision as any) + 1,
update_date: full_report_to_publish.update_date,
update_date: convert(LocalDateTime.now(ZoneId.UTC)).toDate(),
update_user: full_report_to_publish.update_user,
pay_transparency_calculated_data: {
createMany: {
Expand Down