From a2eb16b450154f8af8feb1aca8791b873e63f72e Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 24 May 2024 10:51:58 +0200 Subject: [PATCH] AB#27286 warning date trigger event --- .../dto/notification-date-per-event.dto.ts | 21 +++++++- .../email/email-template.service.ts | 34 ++++++++----- .../notification/email/html/body-event.html | 17 ++++++- .../notification-content.service.ts | 49 +++++++++++++++++-- 4 files changed, 103 insertions(+), 18 deletions(-) diff --git a/services/API-service/src/api/notification/dto/notification-date-per-event.dto.ts b/services/API-service/src/api/notification/dto/notification-date-per-event.dto.ts index 8389691b0..373beeabc 100644 --- a/services/API-service/src/api/notification/dto/notification-date-per-event.dto.ts +++ b/services/API-service/src/api/notification/dto/notification-date-per-event.dto.ts @@ -5,10 +5,29 @@ export class NotificationDataPerEventDto { triggerStatusLabel: TriggerStatusLabelEnum; eventName: string; disasterSpecificCopy: DisasterSpecificCopy; + + /** + * The day that the event starts. + */ firstLeadTime: LeadTime; + + /** + * The day that the event triggers. This could be different from firstLeadTimeString. + * For example, a flood could transition from a warning (a chance of a small flood) + * to an EAP trigger (a larger chance of a bigger flood). + */ + firstTriggerLeadTime: LeadTime; + + firstLeadTimeString: string; + firstTriggerLeadTimeString: string; + triggeredAreas: TriggeredArea[]; + + /** + * The number of areas where the event triggers. + */ nrOfTriggeredAreas: number; - startDateDisasterString: string; + totalAffectedOfIndicator: number; mapImage?: Buffer; issuedDate: Date; 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 5b676aaec..c58a3a66e 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 @@ -323,38 +323,50 @@ export class EmailTemplateService { return emailContent.dataPerEvent .map((event) => { const data = { + // Event details + eventName: event.eventName, hazard: emailContent.disasterTypeLabel, triggerStatusLabel: event.triggerStatusLabel, - eventName: event.eventName, - nrOfTriggeredAreas: event.nrOfTriggeredAreas, - expectedTriggerDate: event.firstLeadTime, issuedDate: this.dateObjectToDateTimeString( event.issuedDate, emailContent.country.countryCodeISO3, ), - startDateEventString: event.startDateDisasterString, + timezone: + CountryTimeZoneMapping[emailContent.country.countryCodeISO3], + + // Lead time details + firstLeadTimeString: event.firstLeadTimeString, + firstTriggerLeadTimeString: event.firstTriggerLeadTimeString, + firstLeadTimeQuantity: event.firstLeadTime.replace('-', ' '), + firstTriggerLeadTimeQuantity: event.firstTriggerLeadTime + ? event.firstTriggerLeadTime.replace('-', ' ') + : '', + + // Area details + nrOfTriggeredAreas: event.nrOfTriggeredAreas, defaultAdminAreaLabel: emailContent.defaultAdminAreaLabel.plural.toLocaleLowerCase(), + + // Indicator details indicatorLabel: emailContent.indicatorMetadata.label, totalAffectedOfIndicator: formatActionUnitValue( event.totalAffectedOfIndicator, emailContent.indicatorMetadata.numberFormatMap, ), indicatorUnit: emailContent.indicatorMetadata.unit, - timezone: - CountryTimeZoneMapping[emailContent.country.countryCodeISO3], + totalAffected: this.getTotalAffectedHtml( + event, + emailContent.indicatorMetadata.label.toLowerCase(), + ), + + // EAP details triangleIcon: this.getTriangleIcon(event.eapAlertClass?.key), - leadTime: event.firstLeadTime.replace('-', ' '), disasterIssuedLabel: event.eapAlertClass.label, color: this.ibfColorToHex(event.eapAlertClass?.color), advisory: this.getAdvisoryHtml( event.triggerStatusLabel, emailContent.linkEapSop, ), - totalAffected: this.getTotalAffectedHtml( - event, - emailContent.indicatorMetadata.label.toLowerCase(), - ), }; const templateFileName = 'body-event.html'; diff --git a/services/API-service/src/api/notification/email/html/body-event.html b/services/API-service/src/api/notification/email/html/body-event.html index fc7439767..8df8f290c 100644 --- a/services/API-service/src/api/notification/email/html/body-event.html +++ b/services/API-service/src/api/notification/email/html/body-event.html @@ -4,11 +4,26 @@ <%= hazard %> <%= eventName %> + <% if (firstTriggerLeadTimeString) { %> + + <%= hazard %> expected to start on <%= firstLeadTimeString %>, <%= + firstLeadTimeQuantity %>s from now. + + + <%= disasterIssuedLabel %>: + + expected to reach threshold on <%= firstTriggerLeadTimeString %>, <%= + firstTriggerLeadTimeQuantity %>s from now. + + + <% } else { %> <%= disasterIssuedLabel %>: - <%= startDateEventString %>, <%= leadTime %>s from now. + expected on <%= firstLeadTimeString %>, <%= firstLeadTimeQuantity %>s from + now. + <% } %> Expected exposed <%= defaultAdminAreaLabel %>: 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..e221a63e9 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 @@ -167,6 +167,7 @@ export class NotificationContentService { event, ); data.firstLeadTime = event.firstLeadTime; + data.firstTriggerLeadTime = event.firstTriggerLeadTime; data.triggeredAreas = await this.getSortedTriggeredAreas( country, disasterType, @@ -179,11 +180,17 @@ export class NotificationContentService { ); // This looks weird, but as far as I understand the startDate of the event is the day it was first issued data.issuedDate = new Date(event.startDate); - data.startDateDisasterString = await this.getFirstLeadTimeString( + data.firstLeadTimeString = await this.getFirstLeadTimeString( event, event.countryCodeISO3, disasterType, ); + data.firstTriggerLeadTimeString = await this.getFirstTriggerLeadTimeString( + event, + event.countryCodeISO3, + disasterType, + ); + data.totalAffectedOfIndicator = this.getTotalAffectedPerEvent( data.triggeredAreas, ); @@ -290,16 +297,48 @@ export class NotificationContentService { countryCodeISO3: string, disasterType: DisasterType, date?: Date, - ) { + ): Promise { + return this.getEventTimeString( + event.firstLeadTime, + countryCodeISO3, + disasterType, + date, + ); + } + + public async getFirstTriggerLeadTimeString( + event: EventSummaryCountry, + countryCodeISO3: string, + disasterType: DisasterType, + date?: Date, + ): Promise { + if (event.firstTriggerLeadTime) { + return this.getEventTimeString( + event.firstTriggerLeadTime, + countryCodeISO3, + disasterType, + date, + ); + } else { + return null; + } + } + + private async getEventTimeString( + leadTime: LeadTime, + countryCodeISO3: string, + disasterType: DisasterType, + date?: Date, + ): Promise { const startDateFirstEvent = await this.getFirstLeadTimeDate( - Number(event.firstLeadTime.split('-')[0]), - event.firstLeadTime.split('-')[1], + Number(leadTime.split('-')[0]), + leadTime.split('-')[1], countryCodeISO3, disasterType, date, ); const startTimeFirstEvent = await this.getLeadTimeTimestamp( - event.firstLeadTime, + leadTime, countryCodeISO3, disasterType, );