Skip to content

Commit

Permalink
refactor(invitesRouter): type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
SySagar committed Aug 30, 2024
1 parent 19c9769 commit c663a54
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({

Check warning on line 73 in apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts

View workflow job for this annotation

GitHub Actions / Check and Build

'test' is assigned a value but never used
where: eq(
orgInvitations.email,
notification!!.notificationEmailAddress as string

Check failure on line 76 in apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts

View workflow job for this annotation

GitHub Actions / Check and Build

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 76 in apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts

View workflow job for this annotation

GitHub Actions / Check and Build

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 76 in apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts

View workflow job for this annotation

GitHub Actions / Check and Build

Forbidden extra non-null assertion
),
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

Check failure on line 87 in apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts

View workflow job for this annotation

GitHub Actions / Check and Build

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 87 in apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts

View workflow job for this annotation

GitHub Actions / Check and Build

Forbidden extra non-null assertion
),
columns: {
id: true
}
});

if (sentInviteEmails) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Email already invited'
});
}

const orgMemberProfilePublicId = typeIdGenerator('orgMemberProfile');
const orgMemberProfileResponse = await db
Expand Down

0 comments on commit c663a54

Please sign in to comment.