Co-authored-by: alannnc <alannnc@gmail.com> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
56 lines
988 B
TypeScript
56 lines
988 B
TypeScript
import prisma from "@calcom/prisma";
|
|
|
|
export async function joinOrganization({
|
|
organizationId,
|
|
userId,
|
|
}: {
|
|
userId: number;
|
|
organizationId: number;
|
|
}) {
|
|
return await prisma.user.update({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
data: {
|
|
organizationId: organizationId,
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function joinAnyChildTeamOnOrgInvite({ userId, orgId }: { userId: number; orgId: number }) {
|
|
await prisma.$transaction([
|
|
prisma.user.update({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
data: {
|
|
organizationId: orgId,
|
|
},
|
|
}),
|
|
prisma.membership.updateMany({
|
|
where: {
|
|
userId,
|
|
team: {
|
|
id: orgId,
|
|
},
|
|
accepted: false,
|
|
},
|
|
data: {
|
|
accepted: true,
|
|
},
|
|
}),
|
|
prisma.membership.updateMany({
|
|
where: {
|
|
userId,
|
|
team: {
|
|
parentId: orgId,
|
|
},
|
|
accepted: false,
|
|
},
|
|
data: {
|
|
accepted: true,
|
|
},
|
|
}),
|
|
]);
|
|
}
|