From 07f42057fc7f645bc682dbff32bd10ecbc68e14c Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:07:03 +0200 Subject: [PATCH] fix: increase maxWait/Timeout invite members transaction (#12583) --- .../viewer/teams/inviteMember/utils.ts | 73 ++++++++++--------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts b/packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts index fb0a38f8ca..2ea1ed579c 100644 --- a/packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts +++ b/packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts @@ -217,46 +217,49 @@ export async function createNewUsersConnectToOrgIfExists({ autoAcceptEmailDomain?: string; connectionInfoMap: Record>; }) { - await prisma.$transaction(async (tx) => { - for (let index = 0; index < usernamesOrEmails.length; index++) { - const usernameOrEmail = usernamesOrEmails[index]; - const { orgId, autoAccept } = connectionInfoMap[usernameOrEmail]; - const [emailUser, emailDomain] = usernameOrEmail.split("@"); - const username = - emailDomain === autoAcceptEmailDomain - ? slugify(emailUser) - : slugify(`${emailUser}-${emailDomain.split(".")[0]}`); + await prisma.$transaction( + async (tx) => { + for (let index = 0; index < usernamesOrEmails.length; index++) { + const usernameOrEmail = usernamesOrEmails[index]; + const { orgId, autoAccept } = connectionInfoMap[usernameOrEmail]; + const [emailUser, emailDomain] = usernameOrEmail.split("@"); + const username = + emailDomain === autoAcceptEmailDomain + ? slugify(emailUser) + : slugify(`${emailUser}-${emailDomain.split(".")[0]}`); - const createdUser = await tx.user.create({ - data: { - username, - email: usernameOrEmail, - verified: true, - invitedTo: input.teamId, - organizationId: orgId || null, // If the user is invited to a child team, they are automatically added to the parent org - teams: { - create: { - teamId: input.teamId, - role: input.role as MembershipRole, - accepted: autoAccept, // If the user is invited to a child team, they are automatically accepted + const createdUser = await tx.user.create({ + data: { + username, + email: usernameOrEmail, + verified: true, + invitedTo: input.teamId, + organizationId: orgId || null, // If the user is invited to a child team, they are automatically added to the parent org + teams: { + create: { + teamId: input.teamId, + role: input.role as MembershipRole, + accepted: autoAccept, // If the user is invited to a child team, they are automatically accepted + }, }, }, - }, - }); - - // We also need to create the membership in the parent org if it exists - if (parentId) { - await tx.membership.create({ - data: { - teamId: parentId, - userId: createdUser.id, - role: input.role as MembershipRole, - accepted: autoAccept, - }, }); + + // We also need to create the membership in the parent org if it exists + if (parentId) { + await tx.membership.create({ + data: { + teamId: parentId, + userId: createdUser.id, + role: input.role as MembershipRole, + accepted: autoAccept, + }, + }); + } } - } - }); + }, + { timeout: 10000 } + ); } export async function createProvisionalMemberships({