Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move segments back to env AB#23528 #1457

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/API-service/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ module.exports = {
argsIgnorePattern: '^_',
},
],
'@typescript-eslint/camelcase': 'off',
},
};
17 changes: 17 additions & 0 deletions services/API-service/migration/1694173727584-RemoveMailSegments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class RemoveMailSegments1694173727584 implements MigrationInterface {
name = 'RemoveMailSegments1694173727584';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "IBF-app"."notification_info" DROP COLUMN "mailSegment"`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "IBF-app"."notification_info" ADD "mailSegment" json NOT NULL DEFAULT '{}'`,
);
}
}
5 changes: 2 additions & 3 deletions services/API-service/src/api/country/country.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -187,6 +188,7 @@ export class CountryService {
disaster.droughtForecastSeasons
? JSON.parse(JSON.stringify(disaster.droughtForecastSeasons))
: null;

countryDisasterSettingsEntity.droughtEndOfMonthPipeline =
disaster.droughtEndOfMonthPipeline;
countryDisasterSettingsEntity.droughtAreas = disaster.droughtAreas
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,4 @@ export class NotificationInfoDto {
@IsOptional()
@IsString()
public externalEarlyActionForm?: string;

@ApiProperty()
public mailSegment: object;
}
25 changes: 18 additions & 7 deletions services/API-service/src/api/notification/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ export class EmailService {
countryCodeISO3: string,
disasterType: DisasterType,
): Promise<number> {
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(
Expand Down Expand Up @@ -436,6 +440,7 @@ export class EmailService {
disasterType,
events,
);

let leadTimeListShort = '';
let leadTimeListLong = '';
for (const leadTime of country.countryDisasterSettings.find(
Expand All @@ -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}`;
Expand All @@ -481,6 +487,7 @@ export class EmailService {
disasterType,
events,
);

let leadTimeTables = '';
for (const leadTime of country.countryDisasterSettings.find(
(s) => s.disasterType === disasterType,
Expand All @@ -494,6 +501,7 @@ export class EmailService {
disasterType,
event.eventName,
);

if (triggeredLeadTimes[leadTime.leadTimeName] === '1') {
// .. find the right leadtime
const tableForLeadTime = await this.getTableForLeadTime(
Expand Down Expand Up @@ -572,6 +580,7 @@ export class EmailService {
}/event/event-map-image/${countryCodeISO3}/${disasterType}/${
eventName || 'no-name'
}`;

return src;
}

Expand Down Expand Up @@ -653,6 +662,7 @@ export class EmailService {
country.countryDisasterSettings.find(
(s) => s.disasterType === disasterType,
).defaultAdminLevel,

leadTime.leadTimeName,
eventName,
);
Expand All @@ -668,6 +678,7 @@ export class EmailService {
leadTime.leadTimeName as LeadTime,
eventName,
);

const areaTable = `<tr class='notification-alerts-table-row'>
<td align='left'>${area.name}${
area.nameParent ? ' (' + area.nameParent + ')' : ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,4 @@ export class NotificationInfoEntity {

@Column({ nullable: true })
public externalEarlyActionForm: string;

@Column('json', { default: {} })
public mailSegment: JSON;
}
52 changes: 9 additions & 43 deletions services/API-service/src/scripts/json/notification-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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"
}
]
Loading