-
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?
Changes from all commits
d463c61
9ec76c8
cc81943
db40a67
f86864c
4859d6a
247f43a
2789b8e
79550aa
b095f19
b60e09f
e3b7c6b
1f641d4
25e927c
14b0328
037c24d
4fa573f
abad75b
0523303
1646da1
2261aec
d0f0500
775591e
6a9146a
3f4a3ba
4b37245
6a0e9c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule Bokken.BirthdayNotifier do | ||
@moduledoc """ | ||
Executes a task periodically to notify Ninjas on their birthday. | ||
""" | ||
|
||
alias Bokken.Accounts | ||
alias BokkenWeb.EventsEmails | ||
import Bokken.Events.EventAdmin | ||
|
||
def send_happy_birthday_ninjas do | ||
ninjas = Accounts.list_ninjas([:user]) | ||
current_time = Date.utc_today() | ||
|
||
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) | ||
) | ||
end) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ defmodule Bokken.Events.EventAdmin do | |
The admin view config of events | ||
""" | ||
alias Bokken.{Events, Pairings} | ||
alias Bokken.Mailer | ||
|
||
def list_actions(_conn) do | ||
[ | ||
|
@@ -46,4 +47,20 @@ defmodule Bokken.Events.EventAdmin do | |
enrollments_close: nil | ||
] | ||
end | ||
|
||
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 | ||
Comment on lines
+51
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule Bokken.Scheduler do | ||
@moduledoc """ | ||
Standard module to run a cronjob. | ||
""" | ||
use Quantum, otp_app: :bokken | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,13 @@ defmodule BokkenWeb.EventsEmails do | |
|> render_body(:mentor_event_reminder) | ||
end | ||
|
||
def ninja_birthday_email(ninja, to: email) do | ||
base_email(to: email) | ||
|> subject("O CoderDojo Braga deseja-te um feliz aniversário! 🎂") | ||
|> assign(:ninja, ninja) | ||
|> render_body(:ninja_birthday) | ||
end | ||
|
||
defp base_email(to: email) do | ||
new() | ||
|> from({"CoderDojo Braga", "[email protected]"}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<table class="wrapper" style="border-collapse: collapse;table-layout: fixed;min-width: 320px;width: 100%;background-color: #fff;" role="presentation" cellspacing="0" cellpadding="0"> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<div> | ||
<div class="layout one-col fixed-width stack" style="Margin: 0 auto;max-width: 600px;min-width: 320px; width: 320px;width: calc(28000% - 167400px);overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;"> | ||
<div class="layout__inner" style="border-collapse: collapse;display: table;width: 100%;background-color: #ffffff;"> | ||
<div class="column" style="text-align: left;color: #000;font-size: 16px;line-height: 24px;font-family: Avenir,sans-serif;"> | ||
|
||
<div style="Margin-left: 20px;Margin-right: 20px;"> | ||
<div style="mso-line-height-rule: exactly;line-height: 23px;font-size: 1px;"> </div> | ||
</div> | ||
|
||
<div style="Margin-left: 20px;Margin-right: 20px;"> | ||
<div style="mso-line-height-rule: exactly;mso-text-raise: 11px;vertical-align: middle;"> | ||
<h1 style="Margin-top: 16px;Margin-bottom: 20px; text-align:center"> | ||
🥳 Aniversário 🥳 | ||
</h1> | ||
</div> | ||
</div> | ||
|
||
<div style="Margin-left: 20px;Margin-right: 20px;"> | ||
<div style="mso-line-height-rule: exactly;mso-text-raise: 11px;vertical-align: middle;"> | ||
<p style="Margin-top: 16px;Margin-bottom: 20px; text-align:center"> | ||
Olá, <%= @ninja.first_name %>! 👋 | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div style="Margin-left: 20px;Margin-right: 20px;"> | ||
<div style="mso-line-height-rule: exactly;mso-text-raise: 11px;vertical-align: middle;"> | ||
<p style="Margin-top: 16px;Margin-bottom: 20px;"> | ||
O CoderDojo Braga deseja-te um feliz aniversário! 🎂 Esperamos por ti na próxima sessão! 😄 | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div style="mso-line-height-rule: exactly;line-height: 20px;font-size: 20px;"> </div> | ||
|
||
<div style="background-color: #ebebeb;"> | ||
<div class="layout one-col stack" style="Margin: 0 auto;max-width: 600px;min-width: 320px; width: 320px;width: calc(28000% - 167400px);overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;"> | ||
<div class="layout__inner" style="border-collapse: collapse;display: table;width: 100%;"> | ||
<div class="column" style="text-align: left;color: #000;font-size: 16px;line-height: 24px;font-family: Avenir,sans-serif;"> | ||
|
||
<div style="Margin-left: 20px;Margin-right: 20px;"> | ||
<div style="mso-line-height-rule: exactly;line-height: 20px;font-size: 1px;"> </div> | ||
</div> | ||
|
||
<div style="Margin-left: 20px;Margin-right: 20px;"> | ||
<div style="mso-line-height-rule: exactly;line-height: 3px;font-size: 1px;"> </div> | ||
</div> | ||
|
||
<div style="font-size: 12px;font-style: normal;font-weight: normal;line-height: 19px;" align="center"> | ||
<a style="text-decoration: underline;transition: opacity 0.1s ease-in;color: #222d8f;" href="https://coderdojobraga.org/"><img style="border: 0;display: block;height: auto;width: 100%;max-width: 134px;" alt="CoderDojo Braga" src="https://coderdojo-braga.vercel.app/img/logo.svg" width="134"></a> | ||
</div> | ||
|
||
<div style="Margin-left: 20px;Margin-right: 20px;Margin-top: 20px;"> | ||
<div style="mso-line-height-rule: exactly;line-height: 1px;font-size: 1px;"> </div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Olá, <%= @ninja.first_name %>! 👋 | ||
|
||
O CoderDojo Braga deseja-te um feliz aniversário! 🎂 Esperamos por ti na próxima sessão! 😄 |
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
isnil
, 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)