Skip to content

Commit f8fe502

Browse files
authored
Merge pull request #1301 from rodekruis/fix.email-leadtime-bugs
Fix.email leadtime bugs
2 parents b28bcce + e111f29 commit f8fe502

File tree

2 files changed

+66
-68
lines changed

2 files changed

+66
-68
lines changed

services/API-service/src/api/notification/email/email.service.ts

+65-67
Original file line numberDiff line numberDiff line change
@@ -275,67 +275,78 @@ export class EmailService {
275275
event.eventName,
276276
);
277277
if (triggeredLeadTimes[leadTime.leadTimeName] === '1') {
278-
// .. find the right leadtime
279-
const [leadTimeValue, leadTimeUnit] = leadTime.leadTimeLabel.split(
280-
'-',
281-
);
282-
283-
const eventName = event.eventName
284-
? `${event.eventName}`
285-
: this.notificationContentService.firstCharOfWordsToUpper(
286-
(
287-
await this.notificationContentService.getDisaster(
288-
disasterType,
289-
)
290-
).label,
291-
);
292-
293-
const triggerStatus = event.thresholdReached
294-
? 'trigger reached'
295-
: 'trigger not reached';
296-
297-
const dateTimePreposition = leadTimeUnit === 'month' ? 'in' : 'on';
298-
const dateAndTime = this.notificationContentService.getFirstLeadTimeDate(
299-
Number(leadTimeValue),
300-
leadTimeUnit,
301-
);
302-
const disasterSpecificCopy = await this.getDisasterSpecificCopy(
303-
disasterType,
304-
leadTime,
305-
event,
306-
);
307-
const leadTimeFromNow = `${leadTimeValue} ${leadTimeUnit}s`;
308-
309278
// We are hack-misusing 'extraInfo' being filled as a proxy for typhoonNoLandfallYet-boolean
310-
const leadTimeString = disasterSpecificCopy.leadTimeString
311-
? disasterSpecificCopy.leadTimeString
312-
: leadTimeFromNow;
313-
314-
const timestamp = disasterSpecificCopy.timestamp
315-
? ` | ${disasterSpecificCopy.timestamp}`
316-
: '';
317-
318-
leadTimeListShort = `${leadTimeListShort}<li>${eventName}: ${
319-
disasterSpecificCopy.extraInfo ||
320-
leadTime.leadTimeName === LeadTime.hour0
321-
? leadTimeString
322-
: `${dateAndTime}${timestamp} (${leadTimeString})`
279+
leadTimeListShort = `${leadTimeListShort}<li>${
280+
(await this.getLeadTimeListEvent(event, disasterType, leadTime))
281+
.short
282+
}</li>`;
283+
leadTimeListLong = `${leadTimeListLong}<li>${
284+
(await this.getLeadTimeListEvent(event, disasterType, leadTime))
285+
.long
323286
}</li>`;
324-
leadTimeListLong = `${leadTimeListLong}<li>${eventName} - <strong>${triggerStatus}</strong>: ${
325-
disasterSpecificCopy.eventStatus
326-
}${
327-
disasterSpecificCopy.extraInfo ||
328-
leadTime.leadTimeName === LeadTime.hour0
329-
? ''
330-
: ` ${dateTimePreposition} ${dateAndTime}${timestamp} (${leadTimeString})`
331-
}. ${disasterSpecificCopy.extraInfo}</li>`;
332287
}
333288
}
334289
}
335290
}
336291
return { leadTimeListShort, leadTimeListLong };
337292
}
338293

294+
private async getLeadTimeListEvent(
295+
event: EventSummaryCountry,
296+
disasterType: DisasterType,
297+
leadTime: any,
298+
) {
299+
// .. find the right leadtime
300+
const [leadTimeValue, leadTimeUnit] = leadTime.leadTimeLabel.split('-');
301+
302+
const eventName = event.eventName
303+
? `${event.eventName}`
304+
: this.notificationContentService.firstCharOfWordsToUpper(
305+
(await this.notificationContentService.getDisaster(disasterType))
306+
.label,
307+
);
308+
309+
const triggerStatus = event.thresholdReached
310+
? 'trigger reached'
311+
: 'trigger not reached';
312+
313+
const dateTimePreposition = leadTimeUnit === 'month' ? 'in' : 'on';
314+
const dateAndTime = this.notificationContentService.getFirstLeadTimeDate(
315+
Number(leadTimeValue),
316+
leadTimeUnit,
317+
);
318+
const disasterSpecificCopy = await this.getDisasterSpecificCopy(
319+
disasterType,
320+
leadTime,
321+
event,
322+
);
323+
const leadTimeFromNow = `${leadTimeValue} ${leadTimeUnit}s`;
324+
325+
const leadTimeString = disasterSpecificCopy.leadTimeString
326+
? disasterSpecificCopy.leadTimeString
327+
: leadTimeFromNow;
328+
329+
const timestamp = disasterSpecificCopy.timestamp
330+
? ` | ${disasterSpecificCopy.timestamp}`
331+
: '';
332+
return {
333+
short: `${eventName}: ${
334+
disasterSpecificCopy.extraInfo ||
335+
leadTime.leadTimeName === LeadTime.hour0
336+
? leadTimeString
337+
: `${dateAndTime}${timestamp} (${leadTimeString})`
338+
}`,
339+
long: `${eventName} - <strong>${triggerStatus}</strong>: ${
340+
disasterSpecificCopy.eventStatus
341+
}${
342+
disasterSpecificCopy.extraInfo ||
343+
leadTime.leadTimeName === LeadTime.hour0
344+
? ''
345+
: ` ${dateTimePreposition} ${dateAndTime}${timestamp} (${leadTimeString})`
346+
}. ${disasterSpecificCopy.extraInfo}`,
347+
};
348+
}
349+
339350
private async getTriggerOverviewTables(
340351
country: CountryEntity,
341352
disasterType: DisasterType,
@@ -466,24 +477,11 @@ export class EmailService {
466477
name: (await this.notificationContentService.getDisaster(disasterType))
467478
.actionsUnit,
468479
});
469-
const leadTimeValue = leadTime.leadTimeName.split('-')[0];
470-
const leadTimeUnit = leadTime.leadTimeName.split('-')[1];
471-
472-
const zeroHour = leadTime.leadTimeName === LeadTime.hour0;
473-
const disasterSpecificCopy = this.getDisasterSpecificCopy(
474-
disasterType,
475-
leadTime,
476-
event,
477-
);
478480

479481
const tableForLeadTimeStart = `<div>
480482
<strong>${
481-
zeroHour
482-
? disasterSpecificCopy
483-
: `Forecast ${
484-
disasterType === DisasterType.HeavyRain ? 'estimated ' : ''
485-
}${leadTimeValue} ${leadTimeUnit}(s) from`
486-
} today (${this.placeholderToday}):</strong>
483+
(await this.getLeadTimeListEvent(event, disasterType, leadTime)).short
484+
}</strong>
487485
</div>
488486
<table class="notification-alerts-table">
489487
<caption class="notification-alerts-table-caption">The following table lists all the exposed ${adminAreaLabels.plural.toLowerCase()} in order of ${actionUnit.label.toLowerCase()},</caption>

services/API-service/src/api/notification/whatsapp/whatsapp.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class WhatsappService {
226226
);
227227

228228
// Add small delay/sleep to ensure the order in which messages are received
229-
await new Promise(resolve => setTimeout(resolve, 2000));
229+
await new Promise(resolve => setTimeout(resolve, 5000));
230230

231231
const whatsappGroupMessage = this.configureWhatsappGroupMessage(
232232
country,

0 commit comments

Comments
 (0)