Skip to content

Commit

Permalink
fix(backend-external): duplicate results in api (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3k authored May 15, 2024
1 parent 5de97dc commit e7ec224
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit e7ec224

Please sign in to comment.