diff --git a/api/gateway/userGateway.ts b/api/gateway/userGateway.ts index 8c00f29..9ae2424 100644 --- a/api/gateway/userGateway.ts +++ b/api/gateway/userGateway.ts @@ -50,6 +50,30 @@ export async function getUserMembershipExpiryDate( return returnDate; } +export async function isMembershipActive(userEmail: string): Promise { + 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; diff --git a/web/__test__/utils/form-validator/ValidateAll.test.tsx b/web/__test__/utils/form-validator/ValidateAll.test.tsx index 67ed44d..1cee014 100644 --- a/web/__test__/utils/form-validator/ValidateAll.test.tsx +++ b/web/__test__/utils/form-validator/ValidateAll.test.tsx @@ -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 = "test@email.com"; const phoneNumber = "123456789123"; const output = FormValidate.validateAll(name, email, phoneNumber, [ diff --git a/web/__test__/utils/form-validator/ValidateEmail.test.tsx b/web/__test__/utils/form-validator/ValidateEmail.test.tsx index 196e246..495cc77 100644 --- a/web/__test__/utils/form-validator/ValidateEmail.test.tsx +++ b/web/__test__/utils/form-validator/ValidateEmail.test.tsx @@ -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); diff --git a/web/__test__/utils/form-validator/ValidateName.test.tsx b/web/__test__/utils/form-validator/ValidateName.test.tsx index 525afde..b886e03 100644 --- a/web/__test__/utils/form-validator/ValidateName.test.tsx +++ b/web/__test__/utils/form-validator/ValidateName.test.tsx @@ -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); diff --git a/web/__test__/utils/form-validator/ValidatePhoneNumber.test.tsx b/web/__test__/utils/form-validator/ValidatePhoneNumber.test.tsx index 1e25a29..500cf34 100644 --- a/web/__test__/utils/form-validator/ValidatePhoneNumber.test.tsx +++ b/web/__test__/utils/form-validator/ValidatePhoneNumber.test.tsx @@ -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); diff --git a/web/src/utils/FormValidate.ts b/web/src/utils/FormValidate.ts index 7a3a35c..bdd8c98 100644 --- a/web/src/utils/FormValidate.ts +++ b/web/src/utils/FormValidate.ts @@ -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) { @@ -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(