-
Notifications
You must be signed in to change notification settings - Fork 0
feat(registration): add member repository #52
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
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,63 @@ | ||
| import { getPrisma } from "../lib/db/prisma"; | ||
|
|
||
| export async function createMembershipRegistration( | ||
| registration: MemberRegistration, | ||
| ) { | ||
| const memberData = toMemberCreateInput(registration); | ||
| try { | ||
| await getPrisma().member.create({ data: memberData }); | ||
| return { ok: true }; | ||
| } catch (error: unknown) { | ||
| if (error instanceof PrismaClientKnownRequestError) { | ||
| if (error.code === "P2002") { | ||
| return { ok: false, error: { type: "duplicate" } }; | ||
| } | ||
| } | ||
|
|
||
| return { ok: false, error: { type: "database" } }; | ||
| } | ||
| } | ||
|
|
||
| function toMemberCreateInput( | ||
| registration: MemberRegistration, | ||
| ): MemberCreateInput { | ||
| const memberData = { | ||
| // unconditonal fields | ||
| firstName: registration.firstName, | ||
| lastName: registration.lastName, | ||
| email: registration.email, | ||
| linuxSkillLevel: registration.linuxSkillLevel, | ||
| potentialInvolvement: registration.potentialInvolvement, | ||
| discordUsername: registration.discordUsername, | ||
|
|
||
| // shared conditional field | ||
|
Collaborator
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. Can we capitalise comments? |
||
| isConditionalReturningMember: registration.isEligibleReturningUoaStudent, | ||
|
Collaborator
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 forgot to mention we changed the |
||
| }; | ||
|
|
||
| const conditionalData = // non-shared conditional fields | ||
| registration.isEligibleReturningUoaStudent === true | ||
| ? { | ||
| faculty: [], | ||
| upi: registration.upi, | ||
| studentId: registration.studentId, | ||
| isCurrentUoaStudent: registration.isCurrentUoaStudent, | ||
|
Collaborator
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. At the moment, the form does not collect this field for conditional returning members. In the future, we will have a system to retrieve members from the previous year (the details of which are yet to be confirmed with the client), so this might change, but for now it should not be included. |
||
| } | ||
| : registration.isCurrentUoaStudent === true | ||
| ? { | ||
| faculty: registration.faculty, | ||
| programme: registration.programme, | ||
| yearLevel: registration.yearLevel, | ||
| upi: registration.upi, | ||
| studentId: registration.studentId, | ||
| isCurrentUoaStudent: registration.isCurrentUoaStudent, | ||
| } | ||
| : { | ||
| faculty: [], | ||
| primaryAffiliation: registration.primaryAffiliation, | ||
| nonUoaExcerpt: registration.nonUoaExcerpt, | ||
| nonUoaPitch: registration.nonUoaPitch, | ||
| isCurrentUoaStudent: registration.isCurrentUoaStudent, | ||
| }; | ||
|
|
||
| return { ...memberData, ...conditionalData }; | ||
| } | ||
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.
typo