From 247bbb4d8a3b0a850ecf380abddff858dca71df2 Mon Sep 17 00:00:00 2001 From: Ratchet7x5 <36789694+Ratchet7x5@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:45:19 +1300 Subject: [PATCH] feat: add new isMembershipActive function --- api/gateway/userGateway.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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;