From 28a4d0ca47b63bf1687cf8bdb7446223921ecf21 Mon Sep 17 00:00:00 2001 From: jer3k <99355997+jer3k@users.noreply.github.com> Date: Wed, 15 May 2024 13:26:35 -0700 Subject: [PATCH 1/2] fix duplicate results --- backend/src/v1/services/external-consumer-service.ts | 9 +++++---- backend/src/v1/services/report-service.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/src/v1/services/external-consumer-service.ts b/backend/src/v1/services/external-consumer-service.ts index f0ee73aa5..2bfa15790 100644 --- a/backend/src/v1/services/external-consumer-service.ts +++ b/backend/src/v1/services/external-consumer-service.ts @@ -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, @@ -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 diff --git a/backend/src/v1/services/report-service.ts b/backend/src/v1/services/report-service.ts index e034f0b7f..0120496e1 100644 --- a/backend/src/v1/services/report-service.ts +++ b/backend/src/v1/services/report-service.ts @@ -379,6 +379,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( @@ -1271,7 +1279,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: new Date(), update_user: full_report_to_publish.update_user, pay_transparency_calculated_data: { createMany: { From 09b7084cfcd27f48b28863b61d1542a77a7c314f Mon Sep 17 00:00:00 2001 From: jer3k <99355997+jer3k@users.noreply.github.com> Date: Wed, 15 May 2024 14:20:31 -0700 Subject: [PATCH 2/2] use utc date --- backend/src/v1/services/report-service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/v1/services/report-service.ts b/backend/src/v1/services/report-service.ts index 0120496e1..30148e1ee 100644 --- a/backend/src/v1/services/report-service.ts +++ b/backend/src/v1/services/report-service.ts @@ -1,5 +1,6 @@ import { LocalDate, + LocalDateTime, TemporalAdjusters, ZoneId, convert, @@ -1279,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: new Date(), + update_date: convert(LocalDateTime.now(ZoneId.UTC)).toDate(), update_user: full_report_to_publish.update_user, pay_transparency_calculated_data: { createMany: {