-
Notifications
You must be signed in to change notification settings - Fork 1
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
Notify ninjas on their birthday #155
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since a guardian can have more than one ninja, it would make sense to identify the ninja (by its first and last names) on the email body 🙏🏼
Co-authored-by: Nelson Estevão <[email protected]>
…aga/bokken into pp/send-ninja-email-birthday
I haven´t used the "family name" because much probably it will be the same for both ninjas and using only the first one the email looks more personalized. |
…aga/bokken into pp/send-ninja-email-birthday
Co-authored-by: Mário Rodrigues <[email protected]>
Co-authored-by: Nelson Estevão <[email protected]>
Co-authored-by: Nelson Estevão <[email protected]>
ninjas | ||
|> Enum.filter(fn ninja -> | ||
ninja.birthday.month == current_time.month && ninja.birthday.day == current_time.day && | ||
not is_nil(ninja.user) | ||
end) | ||
|> Enum.map(fn ninja -> ninja.user end) | ||
|> send_email(fn user -> | ||
EventsEmails.ninja_birthday_email(user.ninja, | ||
to: Accounts.get_guardian_email_by_ninja(ninja: user) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The situation is as follows. Currently not a single ninja has a registered account, meaning this is basically useless. What we could do is send the email to the guardian if the ninja does not have an account associated with them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But Ninjas are not even supposed to have emails, when I'm using the .email I thought I was sending it to the guardians right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But ninja.user
is nil
, meaning you won't send it regardless. It works fine locally because we don't have ninjas without users associated with them (but we should)
def send_email(users, email) do | ||
users | ||
|> Enum.reduce( | ||
%{success: [], fail: []}, | ||
fn user, accumulator -> | ||
case Mailer.deliver(email.(user)) do | ||
{:ok, _} -> | ||
%{success: [user.email | accumulator[:success]], fail: accumulator[:fail]} | ||
|
||
{:error, _} -> | ||
%{success: [accumulator[:success]], fail: [user.email | accumulator[:fail]]} | ||
end | ||
end | ||
) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR in particular, but I am seeing this function used and duplicated in many different contexts. I think we should create an utils file and put it there. What do you think @RuiL1904?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
Solve the conflicts when you can 🙏 |
No description provided.