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

feat: backend for sending event reminders 📆 #524

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@
- poughe
- katlj
- rafa1510
- imnotrafa
- Meron-b
- gxsoto
- mcdev92
- angel-romero-f
- Ekene-Azubuko
- Dharld
- rod608
- mdg258
- mdg258
Copy link
Collaborator

Choose a reason for hiding this comment

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

Who's mdg258? We should only be adding your own GitHub username in this PR.

Also, make sure that there is exactly 1 blank line at the end of the file (that's what the red circle is signifying is missing)

40 changes: 40 additions & 0 deletions packages/core/src/modules/event/use-cases/event-reminder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { db } from '@oyster/db';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename this file to send-event-reminder to stay consistent with the naming pattern of the other files in this directory

import { type Event } from '@oyster/types';
import { listEventAttendees } from '@/member-profile.server';
import { sendEmail } from '@/modules/notification/use-cases/send-email';
import { StudentActivatedEmail } from '@oyster/email-templates';
imnotrafa marked this conversation as resolved.
Show resolved Hide resolved
export async function eventReminder(input: Event) {
imnotrafa marked this conversation as resolved.
Show resolved Hide resolved
//selects students who are undergrad
let RegisteredStudentIDs: string[] = [];
imnotrafa marked this conversation as resolved.
Show resolved Hide resolved
const eventAttendees = await listEventAttendees({
select: ['eventAttendees.studentId', 'students.email'],
where: {
eventId: input.id,
},
});
//extrack student id for the event attendee
imnotrafa marked this conversation as resolved.
Show resolved Hide resolved
eventAttendees.forEach((attendee) => {
if (attendee.studentId) {
RegisteredStudentIDs.push(attendee.studentId);
}
});
//filter down to just the undergrads that are not register for the event
const unregisteredStudents = await db
.selectFrom('students')
.select(['students.email', 'students.firstName'])
.where('educationLevel', '=', 'undergraduate')
.where('id', 'not in', RegisteredStudentIDs)
.execute();

//Must change the name of the email template being used based on the prupose of the function
imnotrafa marked this conversation as resolved.
Show resolved Hide resolved
//TODO: create an email tenplate for event reminders
imnotrafa marked this conversation as resolved.
Show resolved Hide resolved
unregisteredStudents.forEach((student) => {
sendEmail({
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might face an issue here. Since we're sending so many emails, we'll need to make sure we adhere to any email rate limits imposed by Postmark (which is what we use to send emails). Doing some research gives more precise limits.

However, the logic for sending email batches adhering to rate limits should be done as a worker separate from this function, so we can have this done as part of a separate issue. No worries if you don't want to take this on right now.

I'll also tag @ramiAbdou in case he has any more feedback regarding this

Copy link
Author

Choose a reason for hiding this comment

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

I can take on this new issue right away if possible.

name: 'application-accepted',
to: student.email,
data: {
firstName: student.firstName,
},
});
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

As part of this PR, let's also create the template for the email-specifically event-reminder.tsx which can be placed in packages/email-templates/emails/application-created.tsx. Don't worry too much about all the wording details, but do try to have a general structure similar to the other emails in the emails directory.

This will also requiring adding the reference to the new email template in the right places throughout packages/core/src/modules/notification/use-cases/send-email.ts.