+1








1b5d50c45c
Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Kiran K <mailtokirankk@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
45 lines
1014 B
TypeScript
45 lines
1014 B
TypeScript
import type { TFunction } from "next-i18next";
|
|
|
|
import { createAProfileForAnExistingUser } from "@calcom/lib/createAProfileForAnExistingUser";
|
|
import prisma from "@calcom/prisma";
|
|
import type { UserWithMembership } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/utils";
|
|
|
|
/**
|
|
* This should only be used in a dsync context
|
|
*/
|
|
const inviteExistingUserToOrg = async ({
|
|
user,
|
|
org,
|
|
translation,
|
|
}: {
|
|
user: UserWithMembership;
|
|
org: { id: number; name: string; parent: { name: string } | null };
|
|
translation: TFunction;
|
|
}) => {
|
|
await createAProfileForAnExistingUser({
|
|
user,
|
|
organizationId: org.id,
|
|
});
|
|
|
|
await prisma.user.update({
|
|
where: {
|
|
id: user.id,
|
|
},
|
|
data: {
|
|
organizationId: org.id,
|
|
teams: {
|
|
create: {
|
|
teamId: org.id,
|
|
role: "MEMBER",
|
|
// Since coming from directory assume it'll be verified
|
|
accepted: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return user;
|
|
};
|
|
|
|
export default inviteExistingUserToOrg;
|