Skip to content

Commit

Permalink
Merge branch 'feat/ticket-scanning-page' of https://github.com/UoaWDC…
Browse files Browse the repository at this point in the history
…C/auis-portal into feat/ticket-scanning-page
  • Loading branch information
gmat224 committed Dec 9, 2024
2 parents 6d682c1 + 247bbb4 commit 75a8db2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
24 changes: 24 additions & 0 deletions api/gateway/userGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ export async function getUserMembershipExpiryDate(
return returnDate;
}

export async function isMembershipActive(userEmail: string): Promise<boolean> {
let isActive = false;

if (userEmail === "" || userEmail === undefined || userEmail === null) {
throw new Error(
"isMembershipActive: received invalid type for userEmail: " + userEmail
);
}

let isMember = await db
.select({ isMember: peoples.isMember })
.from(peoples)
.where(eq(peoples.email, userEmail))
.limit(1);

if (isMember.length === 1) {
if (isMember[0].isMember !== undefined || isMember[0].isMember !== null) {
isActive = isMember[0].isMember!;
}
}

return isActive;
}

export async function insertUserTicket(data: {
ticketId: number;
name: string;
Expand Down
3 changes: 2 additions & 1 deletion web/__test__/utils/form-validator/ValidateAll.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ describe("Validate Text", () => {

it("should return false with answers not valid", () => {
const name = "gury";
const answer = "answeransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweranswer";
const answer =
"answeransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweransweranswer";
const email = "[email protected]";
const phoneNumber = "123456789123";
const output = FormValidate.validateAll(name, email, phoneNumber, [
Expand Down
3 changes: 2 additions & 1 deletion web/__test__/utils/form-validator/ValidateEmail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe("Validate Email", () => {
});

it("should return false without an large string", () => {
const email = "1234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345@gmail.com";
const email =
"1234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345@gmail.com";
const output = FormValidate.validateEmail(email);
const expected = false;
expect(output).toEqual(expected);
Expand Down
3 changes: 2 additions & 1 deletion web/__test__/utils/form-validator/ValidateName.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe("Validate Name", () => {
});

it("should return false without an large string", () => {
const name = "1234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345@gmail.com";
const name =
"1234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345@gmail.com";
const output = FormValidate.validateName(name);
const expected = false;
expect(output).toEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe("Validate Phone Number", () => {
});

it("should return false without a large number", () => {
const phoneNumber = "1234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345@gmail.com";
const phoneNumber =
"1234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345@gmail.com";
const output = FormValidate.validatePhoneNumber(phoneNumber);
const expected = false;
expect(output).toEqual(expected);
Expand Down
22 changes: 7 additions & 15 deletions web/src/utils/FormValidate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
export class FormValidate {
static validateEmail(text: string) : boolean {
const regex = (text
static validateEmail(text: string): boolean {
const regex = text
.toLowerCase()
.match(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
))
return (
text.length > 2 &&
text.length < 99 &&
(regex !== null)
);
);
return text.length > 2 && text.length < 99 && regex !== null;
}

static validateName(text: string) {
Expand All @@ -34,13 +30,9 @@ export class FormValidate {

static validatePhoneNumber(text: string) {
const regex = text
.toLowerCase()
.match(/^(([0-9\ \+\_\-\,\.\^\*\?\$\^\#\(\)])|(ext|x)){1,20}$/)
return (
text.length > 6 &&
text.length < 20 &&
(regex !== null)
);
.toLowerCase()
.match(/^(([0-9\ \+\_\-\,\.\^\*\?\$\^\#\(\)])|(ext|x)){1,20}$/);
return text.length > 6 && text.length < 20 && regex !== null;
}

static validateAnswers(
Expand Down

0 comments on commit 75a8db2

Please sign in to comment.