Skip to content
Open
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
63 changes: 63 additions & 0 deletions src/repositories/memberRepository.ts
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,

Check failure on line 4 in src/repositories/memberRepository.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, format, and build

Cannot find name 'MemberRegistration'.
) {
const memberData = toMemberCreateInput(registration);
try {
await getPrisma().member.create({ data: memberData });
return { ok: true };
} catch (error: unknown) {
if (error instanceof PrismaClientKnownRequestError) {

Check failure on line 11 in src/repositories/memberRepository.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, format, and build

Cannot find name 'PrismaClientKnownRequestError'.
if (error.code === "P2002") {

Check failure on line 12 in src/repositories/memberRepository.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, format, and build

'error' is of type 'unknown'.
return { ok: false, error: { type: "duplicate" } };
}
}

return { ok: false, error: { type: "database" } };
}
}

function toMemberCreateInput(
registration: MemberRegistration,

Check failure on line 22 in src/repositories/memberRepository.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, format, and build

Cannot find name 'MemberRegistration'.
): MemberCreateInput {

Check failure on line 23 in src/repositories/memberRepository.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, format, and build

Cannot find name 'MemberCreateInput'.
const memberData = {
// unconditonal fields

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

typo

firstName: registration.firstName,
lastName: registration.lastName,
email: registration.email,
linuxSkillLevel: registration.linuxSkillLevel,
potentialInvolvement: registration.potentialInvolvement,
discordUsername: registration.discordUsername,

// shared conditional field

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we capitalise comments?

isConditionalReturningMember: registration.isEligibleReturningUoaStudent,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I forgot to mention we changed the isEligibleReturningUoaStudent field name to isConditionalReturningMember, so all instances of this should be updated accordingly

};

const conditionalData = // non-shared conditional fields
registration.isEligibleReturningUoaStudent === true
? {
faculty: [],
upi: registration.upi,
studentId: registration.studentId,
isCurrentUoaStudent: registration.isCurrentUoaStudent,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 };
}
Loading