-
Notifications
You must be signed in to change notification settings - Fork 130
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
base: main
Are you sure you want to change the base?
Changes from all commits
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,40 @@ | ||
import { db } from '@oyster/db'; | ||
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. Let's rename this file to |
||
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({ | ||
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. 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 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. I can take on this new issue right away if possible. |
||
name: 'application-accepted', | ||
to: student.email, | ||
data: { | ||
firstName: student.firstName, | ||
}, | ||
}); | ||
}); | ||
} | ||
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. As part of this PR, let's also create the template for the email-specifically This will also requiring adding the reference to the new email template in the right places throughout |
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.
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)