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

Wip.email multi event #1496

Merged
merged 67 commits into from
Jul 15, 2024
Merged

Wip.email multi event #1496

merged 67 commits into from
Jul 15, 2024

Conversation

RubenGeo
Copy link
Collaborator

No description provided.

Copy link
Member

@gulfaraz gulfaraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes introduced in this PR,

  • split email html into smaller components using ejs
  • separated email template code, email sending code, email content gathering code, and event specific code (massive respect for this refactor)
  • rename startDate to issuedDate
  • change in definition for finished events getEventsSummaryTriggerFinishedMail and getFinishedEvent

Suggestions,

  • Could we use an email HTML framework like mjml?
  • Could we use a date library like date-fns?

Note for future refactors: Let's keep the new features in a separate PR from the refactor. If there are features added or removed, it's impossible to track if we've lost some functionality.

Would it be possible to document the notifications logic in a flow chart? Feel free to commit the flow chart image in the notifications folder. So it can be used as documentation coupled with the code.

TLDR; It looks okay - I haven't executed any code in this review. See comments for the merge blocker.

Comment on lines 91 to 108
public async getEventsSummaryTriggerFinishedMail(
countryCodeISO3: string,
disasterType: DisasterType,
): Promise<EventSummaryCountry[]> {
const countryAdminAreaIds = await this.getCountryAdminAreaIds(
countryCodeISO3,
);

// I spend quite some time on trying to figure out what is the right query to get the event finished summary for the trigger closed email
// I came up with the following query but I am not sure if it is correct and how to test it properly
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
const sixDaysAgo = new Date(Date.now() - 6 * 24 * 60 * 60 * 1000);
const whereFilters = {
endDate: Between(sevenDaysAgo, sixDaysAgo),
adminArea: In(countryAdminAreaIds),
disasterType: disasterType,
closed: true,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic here is different from getFinishedEvent. I suggest to confirm this new behaviour with the team before merge. Bcoz we've discussed this I agree your interpretation, the only thing that strongly recommend is to keep the check binary instead of a range. i.e. use LessThan instead of Between.

The reason for this recommendation is that for a binary condition - we have two logical pathways. It is either LessThan or MoreThanOrEqual. If we use Between we have three logical pathways. It is either LessThan, MoreThan, or Between. This makes the code more complex and harder to understand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic here is different from getFinishedEvent. I suggest to confirm this new behaviour with the team before merge. Bcoz we've discussed this I agree your interpretation, the only thing that strongly recommend is to keep the check binary instead of a range. i.e. use LessThan instead of Between.

I did not get to checking this with the rest of the team unfortunately

services/API-service/src/api/event/event.service.ts Outdated Show resolved Hide resolved
Base automatically changed from feat.floods-leadtime-event to master May 21, 2024 15:13
@RubenGeo
Copy link
Collaborator Author

RubenGeo commented May 23, 2024

Thanks for the review! Great that you summarized the changes!

Note for future refactors: Let's keep the new features in a separate PR from the refactor. If there are features added or removed, it's impossible to track if we've lost some functionality.

I get this, and agree that it is sub-optimal

Would it be possible to document the notifications logic in a flow chart? Feel free to commit the flow chart image in the notifications folder. So it can be used as documentation coupled with the code.

Sound like a good idea. I am creating an extra task for this on the task board AB#28230.

Could we use an email HTML framework like mjml?

I also created a separate task for this AB#28231. That probably would have been a better approach from the start. However considering the limit time to complete this work I'd rather first finish the API tests before implementing this.

gulfaraz added 28 commits July 1, 2024 14:38
feat: use date-fns library for date operations
@gulfaraz gulfaraz merged commit 53bc5ff into master Jul 15, 2024
4 checks passed
@gulfaraz gulfaraz deleted the wip.email-multi-event branch July 15, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants