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 6 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
1 change: 1 addition & 0 deletions CONTRIBUTORS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- poughe
- katlj
- rafa1510
- imnotrafa
- Meron-b
- gxsoto
- mcdev92
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { db } from '@oyster/db';
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';
export async function eventReminder(input: Event) {

//selects students who are undergrad
let RegisteredStudentIDs: string[] = [];
const eventAttendees = await listEventAttendees({
select: ['eventAttendees.studentId', 'students.email'],
where: {
eventId: input.id,
},
});

//extract student id for the event attendee
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
//TODO: create an email tenplate for event reminders
unregisteredStudents.forEach((student) => {
sendEmail({
name: 'application-accepted',
to: student.email,
data: {
firstName: student.firstName,
},
});
});
}