From 282f2d00a9c0f335ed1053554c685437b6ddf7ee Mon Sep 17 00:00:00 2001 From: SySagar Date: Fri, 30 Aug 2024 23:46:26 +0530 Subject: [PATCH] refactor(invitesRouter): type checks --- .../routers/orgRouter/users/invitesRouter.ts | 32 +++++++++---------- 1 file changed, 15 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..6f83e320 100644 --- a/apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts +++ b/apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts @@ -71,24 +71,22 @@ export const invitesRouter = router({ // Insert account profile - save ID return db.transaction(async (db) => { //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