Fix transactional usage to use interactive handlers

pull/11421/merge^2
Sean Brydon 2023-09-27 15:14:55 +01:00
parent c30e867147
commit 914161ab08
2 changed files with 44 additions and 28 deletions

View File

@ -15,7 +15,7 @@ import prisma from "@calcom/prisma";
import { IdentityProvider } from "@calcom/prisma/enums";
import { signupSchema, teamMetadataSchema } from "@calcom/prisma/zod-utils";
import { joinOrganization, joinAnyChildTeamOnOrgInvite } from "../utils/organization";
import { joinAnyChildTeamOnOrgInvite } from "../utils/organization";
import { findTokenByToken, throwIfTokenExpired, validateUsernameForTeam } from "../utils/token";
async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
@ -124,14 +124,19 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
},
});
const membership = await prisma.$transaction(async (tx) => {
if (teamMetadata?.isOrganization) {
await joinOrganization({
await tx.user.update({
where: {
id: user.id,
},
data: {
organizationId: team.id,
userId: user.id,
},
});
}
const membership = await prisma.membership.update({
const membership = await tx.membership.update({
where: {
userId_teamId: { userId: user.id, teamId: team.id },
},
@ -139,6 +144,9 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
accepted: true,
},
});
return membership;
});
closeComUpsertTeamUser(team, user, membership.role);
// Accept any child team invites for orgs.

View File

@ -12,7 +12,7 @@ import { IdentityProvider } from "@calcom/prisma/enums";
import { signupSchema } from "@calcom/prisma/zod-utils";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
import { joinAnyChildTeamOnOrgInvite, joinOrganization } from "../utils/organization";
import { joinAnyChildTeamOnOrgInvite } from "../utils/organization";
import { findTokenByToken, throwIfTokenExpired, validateUsernameForTeam } from "../utils/token";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
@ -66,14 +66,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
});
const membership = await prisma.$transaction(async (tx) => {
if (teamMetadata?.isOrganization) {
await joinOrganization({
await tx.user.update({
where: {
id: user.id,
},
data: {
organizationId: team.id,
userId: user.id,
},
});
}
const membership = await prisma.membership.update({
const membership = await tx.membership.update({
where: {
userId_teamId: { userId: user.id, teamId: team.id },
},
@ -81,6 +86,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
accepted: true,
},
});
return membership;
});
closeComUpsertTeamUser(team, user, membership.role);
// Accept any child team invites for orgs.