fix: increase maxWait/Timeout invite members transaction (#12583)
This commit is contained in:
1 parent
79ee7c41b2
commit
07f42057fc
1 file changed
+38
-35
@@ -217,46 +217,49 @@ export async function createNewUsersConnectToOrgIfExists({
|
|||||||
autoAcceptEmailDomain?: string;
|
autoAcceptEmailDomain?: string;
|
||||||
connectionInfoMap: Record<string, ReturnType<typeof getOrgConnectionInfo>>;
|
connectionInfoMap: Record<string, ReturnType<typeof getOrgConnectionInfo>>;
|
||||||
}) {
|
}) {
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(
|
||||||
for (let index = 0; index < usernamesOrEmails.length; index++) {
|
async (tx) => {
|
||||||
const usernameOrEmail = usernamesOrEmails[index];
|
for (let index = 0; index < usernamesOrEmails.length; index++) {
|
||||||
const { orgId, autoAccept } = connectionInfoMap[usernameOrEmail];
|
const usernameOrEmail = usernamesOrEmails[index];
|
||||||
const [emailUser, emailDomain] = usernameOrEmail.split("@");
|
const { orgId, autoAccept } = connectionInfoMap[usernameOrEmail];
|
||||||
const username =
|
const [emailUser, emailDomain] = usernameOrEmail.split("@");
|
||||||
emailDomain === autoAcceptEmailDomain
|
const username =
|
||||||
? slugify(emailUser)
|
emailDomain === autoAcceptEmailDomain
|
||||||
: slugify(`${emailUser}-${emailDomain.split(".")[0]}`);
|
? slugify(emailUser)
|
||||||
|
: slugify(`${emailUser}-${emailDomain.split(".")[0]}`);
|
||||||
|
|
||||||
const createdUser = await tx.user.create({
|
const createdUser = await tx.user.create({
|
||||||
data: {
|
data: {
|
||||||
username,
|
username,
|
||||||
email: usernameOrEmail,
|
email: usernameOrEmail,
|
||||||
verified: true,
|
verified: true,
|
||||||
invitedTo: input.teamId,
|
invitedTo: input.teamId,
|
||||||
organizationId: orgId || null, // If the user is invited to a child team, they are automatically added to the parent org
|
organizationId: orgId || null, // If the user is invited to a child team, they are automatically added to the parent org
|
||||||
teams: {
|
teams: {
|
||||||
create: {
|
create: {
|
||||||
teamId: input.teamId,
|
teamId: input.teamId,
|
||||||
role: input.role as MembershipRole,
|
role: input.role as MembershipRole,
|
||||||
accepted: autoAccept, // If the user is invited to a child team, they are automatically accepted
|
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({
|
export async function createProvisionalMemberships({
|
||||||
|
|||||||
Reference in new issue
Block a user