From c663a5461a4335000c2f2a3d3f2d8d8bb8965a5d Mon Sep 17 00:00:00 2001 From: SySagar Date: Fri, 30 Aug 2024 23:19:21 +0530 Subject: [PATCH] refactor(invitesRouter): type checks --- .../routers/orgRouter/users/invitesRouter.ts | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts b/apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts index 5fd8e02f..30d79250 100644 --- a/apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts +++ b/apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts @@ -70,25 +70,33 @@ export const invitesRouter = router({ // Insert account profile - save ID return db.transaction(async (db) => { + const test = await db.query.orgInvitations.findFirst({ + where: eq( + orgInvitations.email, + notification!!.notificationEmailAddress as string + ), + columns: { + id: true + } + }); + //check existing email invite - await db.query.orgInvitations - .findFirst({ - where: eq( - orgInvitations.email, - notification?.notificationEmailAddress as string - ), - columns: { - id: true - } - }) - .then((res: any) => { - if (res) { - throw new TRPCError({ - code: 'UNPROCESSABLE_CONTENT', - message: 'Email already invited' - }); - } + const sentInviteEmails = await db.query.orgInvitations.findFirst({ + where: eq( + orgInvitations.email, + notification!!.notificationEmailAddress + ), + columns: { + id: true + } + }); + + if (sentInviteEmails) { + throw new TRPCError({ + code: 'BAD_REQUEST', + message: 'Email already invited' }); + } const orgMemberProfilePublicId = typeIdGenerator('orgMemberProfile'); const orgMemberProfileResponse = await db