Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logs for duplicate invite #758

Merged
merged 4 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 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,24 @@

// Insert account profile - save ID
return db.transaction(async (db) => {
//check existing email invite
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
.insert(orgMemberProfiles)
Expand Down Expand Up @@ -227,17 +245,25 @@
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 261 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
SySagar marked this conversation as resolved.
Show resolved Hide resolved
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) => {
BlankParticle marked this conversation as resolved.
Show resolved Hide resolved
console.error('Error creating invite', error.message);
}
});

Expand Down
Loading