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