Skip to content

Commit

Permalink
OrganizationRepository use CreateUserService when creating new owner
Browse files Browse the repository at this point in the history
  • Loading branch information
joeauyeung committed Feb 9, 2025
1 parent b7cdc6c commit 24628c3
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/lib/server/repository/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { getOrgUsernameFromEmail } from "@calcom/features/auth/signup/utils/getO
import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import { UserCreationService } from "@calcom/lib/server/service/UserCreationService";
import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
import type { CreationSource } from "@calcom/prisma/enums";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";

import { createAProfileForAnExistingUser } from "../../createAProfileForAnExistingUser";
import { getParsedTeam } from "./teamUtils";
import { UserRepository } from "./user";

const orgSelect = {
id: true,
Expand Down Expand Up @@ -86,19 +86,16 @@ export class OrganizationRepository {
logger.debug("createWithNonExistentOwner", safeStringify({ orgData, owner }));
const organization = await this.create(orgData);
const ownerUsernameInOrg = getOrgUsernameFromEmail(owner.email, orgData.autoAcceptEmail);
const ownerInDb = await UserRepository.create({
email: owner.email,
username: ownerUsernameInOrg,
organizationId: organization.id,
creationSource,
});

await prisma.membership.create({
const ownerInDb = await UserCreationService.createUser({
data: {
userId: ownerInDb.id,
email: owner.email,
username: ownerUsernameInOrg,
creationSource,
},
orgData: {
id: organization.id,
role: MembershipRole.OWNER,
accepted: true,
teamId: organization.id,
},
});

Expand Down

0 comments on commit 24628c3

Please sign in to comment.