From 0415d9630610c897e4751dbd8cbe557972c38ea5 Mon Sep 17 00:00:00 2001 From: Gulfaraz Rahman Date: Mon, 1 Jul 2024 14:37:51 +0200 Subject: [PATCH] fix: email module should not assume that eap alert class is required --- services/API-service/src/api/event/event.service.ts | 5 ++++- .../src/api/notification/email/email-template.service.ts | 5 ++++- .../notification-content/notification-content.service.ts | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/services/API-service/src/api/event/event.service.ts b/services/API-service/src/api/event/event.service.ts index 794a2e8b5..9b203b0e9 100644 --- a/services/API-service/src/api/event/event.service.ts +++ b/services/API-service/src/api/event/event.service.ts @@ -158,7 +158,10 @@ export class EventService { event.eventName, ); } - if (disasterSettings.eapAlertClasses) { + if (disasterType === DisasterType.Floods) { + // REFACTOR: either make eapAlertClass a requirement across all hazard + // types or reimplement such that eapAlertClass is not needed in the + // backend (it is a VIEW of the DATA in the dashboard and email) event.disasterSpecificProperties = await this.getEventEapAlertClass( disasterSettings, event.triggerValue, diff --git a/services/API-service/src/api/notification/email/email-template.service.ts b/services/API-service/src/api/notification/email/email-template.service.ts index c3ae60ed0..e3b0aca78 100644 --- a/services/API-service/src/api/notification/email/email-template.service.ts +++ b/services/API-service/src/api/notification/email/email-template.service.ts @@ -340,7 +340,10 @@ export class EmailTemplateService { CountryTimeZoneMapping[emailContent.country.countryCodeISO3], triangleIcon: this.getTriangleIcon(event.eapAlertClass?.key), leadTime: event.firstLeadTime.replace('-', ' '), - disasterIssuedLabel: event.eapAlertClass.label, + disasterIssuedLabel: + event.eapAlertClass?.label ?? event.triggerStatusLabel, + // REFACTOR: avoid the logic fork in disasterIssuedLabel + // use the same label variable across all hazard types color: this.ibfColorToHex(event.eapAlertClass?.color), advisory: this.getAdvisoryHtml( event.triggerStatusLabel, diff --git a/services/API-service/src/api/notification/notification-content/notification-content.service.ts b/services/API-service/src/api/notification/notification-content/notification-content.service.ts index ec5eaffdf..24c491191 100644 --- a/services/API-service/src/api/notification/notification-content/notification-content.service.ts +++ b/services/API-service/src/api/notification/notification-content/notification-content.service.ts @@ -192,7 +192,7 @@ export class NotificationContentService { disasterType, event.eventName || 'no-name', ); - data.eapAlertClass = event.disasterSpecificProperties.eapAlertClass; + data.eapAlertClass = event.disasterSpecificProperties?.eapAlertClass; return data; }