Skip to content

Commit

Permalink
fix: logs for duplicate invite
Browse files Browse the repository at this point in the history
  • Loading branch information
SySagar committed Aug 30, 2024
1 parent ab7105c commit 19c9769
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
50 changes: 39 additions & 11 deletions apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ 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

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

View workflow job for this annotation

GitHub Actions / Check and Build

Use a ! assertion to more succinctly remove null and undefined from the type

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

View workflow job for this annotation

GitHub Actions / autofix

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
),
columns: {
id: true
}
})
.then((res: any) => {

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

View workflow job for this annotation

GitHub Actions / Check and Build

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type
if (res) {
throw new TRPCError({
code: 'UNPROCESSABLE_CONTENT',
message: 'Email already invited'
});
}
});

const orgMemberProfilePublicId = typeIdGenerator('orgMemberProfile');
const orgMemberProfileResponse = await db
.insert(orgMemberProfiles)
Expand Down Expand Up @@ -227,17 +247,25 @@ export const invitesRouter = router({
const newInvitePublicId = typeIdGenerator('orgInvitations');
const newInviteToken = nanoIdToken();

await db.insert(orgInvitations).values({
publicId: newInvitePublicId,
orgId: orgId,
invitedByOrgMemberId: orgMemberId,
orgMemberId: +newOrgMemberResponse.insertId,
role: newOrgMember.role,
email: notification?.notificationEmailAddress ?? null,
inviteToken: newInviteToken,
invitedOrgMemberProfileId: orgMemberProfileId,
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000) // 7 Days from now
});
await db
.insert(orgInvitations)
.values({
publicId: newInvitePublicId,
orgId: orgId,
invitedByOrgMemberId: orgMemberId,
orgMemberId: +newOrgMemberResponse.insertId,
role: newOrgMember.role,
email: notification?.notificationEmailAddress ?? null,
inviteToken: newInviteToken,
invitedOrgMemberProfileId: orgMemberProfileId,
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000) // 7 Days from now
})
.catch((err) => {

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

View workflow job for this annotation

GitHub Actions / Check and Build

'err' is defined but never used. Allowed unused args must match /^_/u

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

View workflow job for this annotation

GitHub Actions / autofix

'err' is defined but never used. Allowed unused args must match /^_/u
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: 'Failed to create invite'
});
});

if (notification?.notificationEmailAddress) {
const res = await sendInviteEmail({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export function InviteModal() {
form.reset();
void invalidateInvites.invalidate();
setOpen(false);
},
onError: (error) => {
console.error('Error creating invite', error.message);
}
});

Expand Down

0 comments on commit 19c9769

Please sign in to comment.