Notify ninjas on their birthday#155
Conversation
ruilopesm
left a comment
There was a problem hiding this comment.
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 <nelsonmestevao@gmail.com>
…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 <93675410+MarioRodrigues10@users.noreply.github.com>
Co-authored-by: Nelson Estevão <nelsonmestevao@gmail.com>
Co-authored-by: Nelson Estevão <nelsonmestevao@gmail.com>
| 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.
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.
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.
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.
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?
|
Solve the conflicts when you can 🙏 |
No description provided.