Files
calendar/packages/features/ee/dsync/lib/inviteExistingUserToOrg.ts
T
Benny JooGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ae31e05bec refactor: decouple @calcom/features from @calcom/trpc/server [2] (#27821)
* inviteMemberUtils in featuers

* update imports

* wip

* wip

* fix: remove PII from log statements in inviteMemberUtils

- Remove email (usernameOrEmail) from error log in sendSignupToOrganizationEmail
- Replace full user object with userId in debug log in sendExistingUserTeamInviteEmails

Co-Authored-By: unknown <>

* revert: restore original code for pure relocation (no formatting/logic changes)

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* fix

* fix: update test mocks to use new import path for inviteMemberUtils

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* revert: restore original formatting in proration test and handleGroupEvents

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-02-10 09:29:32 -03:00

54 lines
1.4 KiB
TypeScript

import type { UserWithMembership } from "@calcom/features/ee/teams/lib/inviteMemberUtils";
import { sendExistingUserTeamInviteEmails } from "@calcom/features/ee/teams/lib/inviteMemberUtils";
import { createAProfileForAnExistingUser } from "@calcom/features/profile/lib/createAProfileForAnExistingUser";
import prisma from "@calcom/prisma";
import type { TFunction } from "i18next";
/**
* 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,
},
},
},
});
await sendExistingUserTeamInviteEmails({
currentUserName: user.username,
currentUserTeamName: org.name,
existingUsersWithMemberships: [user],
language: translation,
isOrg: true,
teamId: org.id,
isAutoJoin: true,
currentUserParentTeamName: org?.parent?.name,
});
};
export default inviteExistingUserToOrg;