diff --git a/services/API-service/.eslintrc.js b/services/API-service/.eslintrc.js index bf3ba1181..90684e14e 100644 --- a/services/API-service/.eslintrc.js +++ b/services/API-service/.eslintrc.js @@ -20,5 +20,6 @@ module.exports = { argsIgnorePattern: '^_', }, ], + '@typescript-eslint/camelcase': 'off', }, }; diff --git a/services/API-service/migration/1694173727584-RemoveMailSegments.ts b/services/API-service/migration/1694173727584-RemoveMailSegments.ts new file mode 100644 index 000000000..954d6e60b --- /dev/null +++ b/services/API-service/migration/1694173727584-RemoveMailSegments.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class RemoveMailSegments1694173727584 implements MigrationInterface { + name = 'RemoveMailSegments1694173727584'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "IBF-app"."notification_info" DROP COLUMN "mailSegment"`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "IBF-app"."notification_info" ADD "mailSegment" json NOT NULL DEFAULT '{}'`, + ); + } +} diff --git a/services/API-service/src/api/country/country.service.ts b/services/API-service/src/api/country/country.service.ts index b6179e73f..b5ddf43eb 100644 --- a/services/API-service/src/api/country/country.service.ts +++ b/services/API-service/src/api/country/country.service.ts @@ -179,6 +179,7 @@ export class CountryService { disaster.adminLevels as AdminLevel[]; countryDisasterSettingsEntity.defaultAdminLevel = disaster.defaultAdminLevel as AdminLevel; + countryDisasterSettingsEntity.eapLink = disaster.eapLink; countryDisasterSettingsEntity.eapAlertClasses = disaster.eapAlertClasses ? JSON.parse(JSON.stringify([disaster.eapAlertClasses]))[0] @@ -187,6 +188,7 @@ export class CountryService { disaster.droughtForecastSeasons ? JSON.parse(JSON.stringify(disaster.droughtForecastSeasons)) : null; + countryDisasterSettingsEntity.droughtEndOfMonthPipeline = disaster.droughtEndOfMonthPipeline; countryDisasterSettingsEntity.droughtAreas = disaster.droughtAreas @@ -277,9 +279,6 @@ export class CountryService { } notificationInfoEntity.externalEarlyActionForm = notificationInfoCountry.externalEarlyActionForm; - notificationInfoEntity.mailSegment = JSON.parse( - JSON.stringify(notificationInfoCountry.mailSegment), - ); const saveResult = await this.notificationInfoRepository.save( notificationInfoEntity, diff --git a/services/API-service/src/api/country/dto/notification-info.dto.ts b/services/API-service/src/api/country/dto/notification-info.dto.ts index 110dcc165..bd27c5d29 100644 --- a/services/API-service/src/api/country/dto/notification-info.dto.ts +++ b/services/API-service/src/api/country/dto/notification-info.dto.ts @@ -40,7 +40,4 @@ export class NotificationInfoDto { @IsOptional() @IsString() public externalEarlyActionForm?: string; - - @ApiProperty() - public mailSegment: object; } diff --git a/services/API-service/src/api/notification/email/email.service.ts b/services/API-service/src/api/notification/email/email.service.ts index de9e03bc4..4a7de6387 100644 --- a/services/API-service/src/api/notification/email/email.service.ts +++ b/services/API-service/src/api/notification/email/email.service.ts @@ -35,15 +35,19 @@ export class EmailService { countryCodeISO3: string, disasterType: DisasterType, ): Promise { - const notificationInfo = ( - await this.notificationContentService.getCountryNotificationInfo( - countryCodeISO3, - ) - ).notificationInfo; - if (!notificationInfo || !notificationInfo.mailSegment[disasterType]) { + const segments: { + [countryDisaster: string]: string; + } = process.env.MC_SEGMENTS.split(',').reduce((prev, curr) => { + const segment = curr.split(':'); + return { ...prev, [segment[0]]: Number(segment[1]) }; + }, {}); + + const countryDisaster = `${countryCodeISO3}_${disasterType}`; + if (!segments || !segments[countryDisaster]) { return null; } - return notificationInfo.mailSegment[disasterType]; + + return Number(segments[countryDisaster]); } public async sendTriggerEmail( @@ -436,6 +440,7 @@ export class EmailService { disasterType, events, ); + let leadTimeListShort = ''; let leadTimeListLong = ''; for (const leadTime of country.countryDisasterSettings.find( @@ -459,6 +464,7 @@ export class EmailService { leadTime.leadTimeName as LeadTime, date, ); + // We are hack-misusing 'extraInfo' being filled as a proxy for typhoonNoLandfallYet-boolean leadTimeListShort = `${leadTimeListShort}${leadTimeListEvent.short}`; leadTimeListLong = `${leadTimeListLong}${leadTimeListEvent.long}`; @@ -481,6 +487,7 @@ export class EmailService { disasterType, events, ); + let leadTimeTables = ''; for (const leadTime of country.countryDisasterSettings.find( (s) => s.disasterType === disasterType, @@ -494,6 +501,7 @@ export class EmailService { disasterType, event.eventName, ); + if (triggeredLeadTimes[leadTime.leadTimeName] === '1') { // .. find the right leadtime const tableForLeadTime = await this.getTableForLeadTime( @@ -572,6 +580,7 @@ export class EmailService { }/event/event-map-image/${countryCodeISO3}/${disasterType}/${ eventName || 'no-name' }`; + return src; } @@ -653,6 +662,7 @@ export class EmailService { country.countryDisasterSettings.find( (s) => s.disasterType === disasterType, ).defaultAdminLevel, + leadTime.leadTimeName, eventName, ); @@ -668,6 +678,7 @@ export class EmailService { leadTime.leadTimeName as LeadTime, eventName, ); + const areaTable = ` ${area.name}${ area.nameParent ? ' (' + area.nameParent + ')' : '' diff --git a/services/API-service/src/api/notification/notifcation-info.entity.ts b/services/API-service/src/api/notification/notifcation-info.entity.ts index fcf9a0c76..981fc5100 100644 --- a/services/API-service/src/api/notification/notifcation-info.entity.ts +++ b/services/API-service/src/api/notification/notifcation-info.entity.ts @@ -33,7 +33,4 @@ export class NotificationInfoEntity { @Column({ nullable: true }) public externalEarlyActionForm: string; - - @Column('json', { default: {} }) - public mailSegment: JSON; } diff --git a/services/API-service/src/scripts/json/notification-info.json b/services/API-service/src/scripts/json/notification-info.json index a8b462877..c82f709c6 100644 --- a/services/API-service/src/scripts/json/notification-info.json +++ b/services/API-service/src/scripts/json/notification-info.json @@ -29,12 +29,7 @@ } }, "linkVideo": "https://bit.ly/IBF-video-Uganda", - "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Uganda-Published.pdf", - "mailSegment": { - "drought": 102274, - "floods": 2525654, - "heavy-rain": 2539574 - } + "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Uganda-Published.pdf" }, { "countryCodeISO3": "PHL", @@ -51,12 +46,7 @@ "linkSocialMediaType": null, "linkSocialMediaUrl": null, "linkVideo": "https://bit.ly/IBF-video-Philippines", - "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Philippines-Published.pdf", - "mailSegment": { - "dengue": 105802, - "floods": 2525658, - "typhoon": 2525662 - } + "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Philippines-Published.pdf" }, { "countryCodeISO3": "ZMB", @@ -69,10 +59,7 @@ "linkSocialMediaType": "WhatsApp", "linkSocialMediaUrl": "https://chat.whatsapp.com/Ca2QYoYjKhyKm6zaZxOnin/", "linkVideo": "https://bit.ly/IBF-video-Zambia", - "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Zambia-Published.pdf", - "mailSegment": { - "floods": 90286 - } + "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Zambia-Published.pdf" }, { "countryCodeISO3": "KEN", @@ -87,11 +74,7 @@ "linkSocialMediaType": "WhatsApp", "linkSocialMediaUrl": "https://chat.whatsapp.com/EbJ5kjSNlK018vkYwt5v5K/", "linkVideo": "https://bit.ly/IBF-video-Kenya", - "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Kenya-Published.pdf", - "mailSegment": { - "drought": 90702, - "floods": 2525674 - } + "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Kenya-Published.pdf" }, { "countryCodeISO3": "ETH", @@ -108,12 +91,7 @@ "linkSocialMediaType": "WhatsApp", "linkSocialMediaUrl": "https://chat.whatsapp.com/Ibj8FcZwFxQLBcuMGUkrms/", "linkVideo": "https://bit.ly/IBF-video-Ethiopia", - "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Ethiopia-Published.pdf", - "mailSegment": { - "drought": 90706, - "floods": 2525678, - "malaria": 2525682 - } + "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Ethiopia-Published.pdf" }, { "countryCodeISO3": "EGY", @@ -126,10 +104,7 @@ "linkSocialMediaType": "Telegram", "linkSocialMediaUrl": "https://t.me/joinchat/hLtvficJO-llZDE0/", "linkVideo": "https://bit.ly/IBF-video-Egypt", - "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Egypt-Published.pdf", - "mailSegment": { - "heavy-rain": 100810 - } + "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Egypt-Published.pdf" }, { "countryCodeISO3": "ZWE", @@ -142,10 +117,7 @@ "linkSocialMediaType": "WhatsApp", "linkSocialMediaUrl": "https://chat.whatsapp.com/FfVimuGRHHiJSk0BU7nGQT/", "linkVideo": "https://bit.ly/IBF-video-Zimbabwe", - "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Zimbabwe-Published.pdf", - "mailSegment": { - "drought": 105794 - } + "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Zimbabwe-Published.pdf" }, { "countryCodeISO3": "MWI", @@ -161,10 +133,7 @@ "linkSocialMediaUrl": "https://chat.whatsapp.com/", "linkVideo": "https://bit.ly/IBF-video-Malawi", "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-Malawi-Published.pdf", - "mailSegment": { - "floods": 2163966, - "flash-floods": 2525790 - }, + "useWhatsapp": { "flash-floods": true, "floods": false @@ -205,9 +174,6 @@ }, "externalEarlyActionForm": "https://eenew.ifrc.org/x/o3VEUuQG", "linkVideo": "https://bit.ly/IBF-video-SouthSudan", - "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-South%20Sudan-Published.pdf", - "mailSegment": { - "floods": 2520726 - } + "linkPdf": "https://510ibfsystem.blob.core.windows.net/manuals/IBF%20Manual-South%20Sudan-Published.pdf" } ]