From 1e1b157cc783d902d97379f924ea700b5617455a Mon Sep 17 00:00:00 2001 From: abradat Date: Fri, 6 Sep 2024 13:36:20 -0700 Subject: [PATCH] Fix "For Discussion" column showing the furthest date instead of closest one --- .../application-decision-meeting.service.ts | 24 +++++++++++++++++-- .../planning-review-meeting.service.ts | 12 +++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/services/apps/alcs/src/alcs/application/application-decision-meeting/application-decision-meeting.service.ts b/services/apps/alcs/src/alcs/application/application-decision-meeting/application-decision-meeting.service.ts index 59d660199a..57dbb5a96d 100644 --- a/services/apps/alcs/src/alcs/application/application-decision-meeting/application-decision-meeting.service.ts +++ b/services/apps/alcs/src/alcs/application/application-decision-meeting/application-decision-meeting.service.ts @@ -131,7 +131,17 @@ export class ApplicationDecisionMeetingService { > { return await this.appDecisionMeetingRepository .createQueryBuilder('meeting') - .select('reconsideration.uuid, MAX(meeting.date) as next_meeting') + .select('reconsideration.uuid', 'uuid') + .addSelect( + ` + CASE + WHEN MIN(CASE WHEN meeting.date >= (CURRENT_DATE) THEN meeting.date END) is NOT NULL + THEN MIN(CASE WHEN meeting.date >= (CURRENT_DATE) THEN meeting.date END) + ELSE MAX(CASE WHEN meeting.date < (CURRENT_DATE) THEN meeting.date END) + END + `, + 'next_meeting', + ) .innerJoin('meeting.application', 'application') .innerJoin('application.reconsiderations', 'reconsideration') .innerJoin('reconsideration.card', 'card') @@ -145,7 +155,17 @@ export class ApplicationDecisionMeetingService { > { return await this.appDecisionMeetingRepository .createQueryBuilder('meeting') - .select('application.uuid, MAX(meeting.date) as next_meeting') + .select('application.uuid', 'uuid') + .addSelect( + ` + CASE + WHEN MIN(CASE WHEN meeting.date >= (CURRENT_DATE) THEN meeting.date END) is NOT NULL + THEN MIN(CASE WHEN meeting.date >= (CURRENT_DATE) THEN meeting.date END) + ELSE MAX(CASE WHEN meeting.date < (CURRENT_DATE) THEN meeting.date END) + END + `, + 'next_meeting', + ) .innerJoin('meeting.application', 'application') .innerJoin('application.card', 'card') .where(`card.status_code != '${CARD_STATUS.DECISION_RELEASED}'`) diff --git a/services/apps/alcs/src/alcs/planning-review/planning-review-meeting/planning-review-meeting.service.ts b/services/apps/alcs/src/alcs/planning-review/planning-review-meeting/planning-review-meeting.service.ts index 82ebe6821c..3df8e7b7d2 100644 --- a/services/apps/alcs/src/alcs/planning-review/planning-review-meeting/planning-review-meeting.service.ts +++ b/services/apps/alcs/src/alcs/planning-review/planning-review-meeting/planning-review-meeting.service.ts @@ -102,7 +102,17 @@ export class PlanningReviewMeetingService { > { return await this.meetingRepository .createQueryBuilder('meeting') - .select('planningReview.uuid, MAX(meeting.date) as next_meeting') + .select('planningReview.uuid', 'uuid') + .addSelect( + ` + CASE + WHEN MIN(CASE WHEN meeting.date >= (CURRENT_DATE) THEN meeting.date END) is NOT NULL + THEN MIN(CASE WHEN meeting.date >= (CURRENT_DATE) THEN meeting.date END) + ELSE MAX(CASE WHEN meeting.date < (CURRENT_DATE) THEN meeting.date END) + END + `, + 'next_meeting', + ) .innerJoin('meeting.planningReview', 'planningReview') .innerJoin('planningReview.referrals', 'referrals') .innerJoin('referrals.card', 'card')