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..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, @@ -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( @@ -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: {