diff --git a/packages/features/ee/billing/api/webhook/_invoice.paid.org.ts b/packages/features/ee/billing/api/webhook/_invoice.paid.org.ts index a5783a3ada..2558804303 100644 --- a/packages/features/ee/billing/api/webhook/_invoice.paid.org.ts +++ b/packages/features/ee/billing/api/webhook/_invoice.paid.org.ts @@ -4,10 +4,10 @@ import { getBillingProviderService } from "@calcom/ee/billing/di/containers/Bill import { Plan, SubscriptionStatus } from "@calcom/features/ee/billing/repository/billing/IBillingRepository"; import { BillingEnabledOrgOnboardingService } from "@calcom/features/ee/organizations/lib/service/onboarding/BillingEnabledOrgOnboardingService"; import stripe from "@calcom/features/ee/payments/server/stripe"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import { UserRepository } from "@calcom/features/users/repositories/UserRepository"; import logger from "@calcom/lib/logger"; import { safeStringify } from "@calcom/lib/safeStringify"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import { prisma } from "@calcom/prisma"; import { getTeamBillingServiceFactory } from "../../di/containers/Billing"; diff --git a/packages/features/ee/organizations/lib/OrganizationPaymentService.ts b/packages/features/ee/organizations/lib/OrganizationPaymentService.ts index 9fa9af0111..3eb50d414c 100644 --- a/packages/features/ee/organizations/lib/OrganizationPaymentService.ts +++ b/packages/features/ee/organizations/lib/OrganizationPaymentService.ts @@ -1,20 +1,16 @@ import { getBillingProviderService } from "@calcom/features/ee/billing/di/containers/Billing"; import type { StripeBillingService } from "@calcom/features/ee/billing/service/billingProvider/StripeBillingService"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import { UserRepository } from "@calcom/features/users/repositories/UserRepository"; -import { - ORGANIZATION_SELF_SERVE_PRICE, - WEBAPP_URL, - ORG_TRIAL_DAYS, -} from "@calcom/lib/constants"; +import { ORGANIZATION_SELF_SERVE_PRICE, WEBAPP_URL, ORG_TRIAL_DAYS } from "@calcom/lib/constants"; +import { ErrorCode } from "@calcom/lib/errorCodes"; +import { ErrorWithCode } from "@calcom/lib/errors"; import logger from "@calcom/lib/logger"; import { safeStringify } from "@calcom/lib/safeStringify"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import { prisma } from "@calcom/prisma"; import type { OrganizationOnboarding } from "@calcom/prisma/client"; import { UserPermissionRole, type BillingPeriod } from "@calcom/prisma/enums"; import { userMetadata } from "@calcom/prisma/zod-utils"; -import { ErrorCode } from "@calcom/lib/errorCodes"; -import { ErrorWithCode } from "@calcom/lib/errors"; import { OrganizationPermissionService } from "./OrganizationPermissionService"; import type { OnboardingUser } from "./service/onboarding/types"; diff --git a/packages/features/ee/organizations/lib/service/onboarding/BaseOnboardingService.ts b/packages/features/ee/organizations/lib/service/onboarding/BaseOnboardingService.ts index aec2473565..5d677155d6 100644 --- a/packages/features/ee/organizations/lib/service/onboarding/BaseOnboardingService.ts +++ b/packages/features/ee/organizations/lib/service/onboarding/BaseOnboardingService.ts @@ -2,14 +2,15 @@ import type { TFunction } from "i18next"; import { sendOrganizationCreationEmail } from "@calcom/emails/organization-email-service"; import { sendEmailVerification } from "@calcom/features/auth/lib/verifyEmail"; +import { getOrganizationRepository } from "@calcom/features/ee/organizations/di/OrganizationRepository.container"; import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains"; import { assertCanCreateOrg, findUserToBeOrgOwner, setupDomain, } from "@calcom/features/ee/organizations/lib/server/orgCreationUtils"; -import { getOrganizationRepository } from "@calcom/features/ee/organizations/di/OrganizationRepository.container"; import { TeamRepository } from "@calcom/features/ee/teams/repositories/TeamRepository"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import { UserRepository } from "@calcom/features/users/repositories/UserRepository"; import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability"; import { WEBAPP_URL } from "@calcom/lib/constants"; @@ -17,7 +18,6 @@ import logger from "@calcom/lib/logger"; import { safeStringify } from "@calcom/lib/safeStringify"; import { uploadLogo } from "@calcom/lib/server/avatar"; import { getTranslation } from "@calcom/lib/server/i18n"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import { isBase64Image, resizeBase64Image } from "@calcom/lib/server/resizeBase64Image"; import slugify from "@calcom/lib/slugify"; import { prisma } from "@calcom/prisma"; @@ -165,9 +165,7 @@ export abstract class BaseOnboardingService implements IOrganizationOnboardingSe } return teams.map((team) => - team.id === conflictingTeam.id - ? { ...team, isBeingMigrated: true } - : team + team.id === conflictingTeam.id ? { ...team, isBeingMigrated: true } : team ); } @@ -270,7 +268,9 @@ export abstract class BaseOnboardingService implements IOrganizationOnboardingSe }): Promise<{ logo?: string | null; bannerUrl?: string | null }> { const [logo, bannerUrl] = await Promise.all([ input.logo ? resizeBase64Image(input.logo) : Promise.resolve(input.logo), - input.bannerUrl ? resizeBase64Image(input.bannerUrl, { maxSize: 1500 }) : Promise.resolve(input.bannerUrl), + input.bannerUrl + ? resizeBase64Image(input.bannerUrl, { maxSize: 1500 }) + : Promise.resolve(input.bannerUrl), ]); return { logo, bannerUrl }; @@ -308,7 +308,9 @@ export abstract class BaseOnboardingService implements IOrganizationOnboardingSe logoUrl?: string | null; bannerUrl?: string | null; }> { - const uploadedLogoUrl = logoUrl ? await this.uploadImageAsset({ image: logoUrl, teamId: organizationId }) : logoUrl; + const uploadedLogoUrl = logoUrl + ? await this.uploadImageAsset({ image: logoUrl, teamId: organizationId }) + : logoUrl; const uploadedBannerUrl = bannerUrl ? await this.uploadImageAsset({ image: bannerUrl, teamId: organizationId, isBanner: true }) @@ -391,11 +393,11 @@ export abstract class BaseOnboardingService implements IOrganizationOnboardingSe organization = { ...orgCreationResult.organization, - ...await this.uploadOrganizationBrandAssets({ + ...(await this.uploadOrganizationBrandAssets({ logoUrl: orgData.logoUrl, bannerUrl: orgData.bannerUrl, organizationId: orgCreationResult.organization.id, - }) + })), }; const ownerProfile = orgCreationResult.ownerProfile; @@ -472,11 +474,11 @@ export abstract class BaseOnboardingService implements IOrganizationOnboardingSe organization = { ...orgCreationResult.organization, - ...await this.uploadOrganizationBrandAssets({ + ...(await this.uploadOrganizationBrandAssets({ logoUrl: orgData.logoUrl, bannerUrl: orgData.bannerUrl, organizationId: orgCreationResult.organization.id, - }) + })), }; const { ownerProfile, orgOwner: orgOwnerFromCreation } = orgCreationResult; @@ -616,7 +618,8 @@ export abstract class BaseOnboardingService implements IOrganizationOnboardingSe } else if (member.teamName) { targetTeamId = teamNameToId.get(member.teamName.toLowerCase()); log.debug( - `Member ${member.email}: teamName "${member.teamName}" -> resolved to ${targetTeamId || "not found" + `Member ${member.email}: teamName "${member.teamName}" -> resolved to ${ + targetTeamId || "not found" }` ); } @@ -758,4 +761,3 @@ export abstract class BaseOnboardingService implements IOrganizationOnboardingSe }); } } - diff --git a/packages/features/ee/organizations/lib/service/onboarding/BillingEnabledOrgOnboardingService.ts b/packages/features/ee/organizations/lib/service/onboarding/BillingEnabledOrgOnboardingService.ts index 3b63e0167f..9f5d0b2390 100644 --- a/packages/features/ee/organizations/lib/service/onboarding/BillingEnabledOrgOnboardingService.ts +++ b/packages/features/ee/organizations/lib/service/onboarding/BillingEnabledOrgOnboardingService.ts @@ -1,10 +1,10 @@ -import { findUserToBeOrgOwner } from "@calcom/features/ee/organizations/lib/server/orgCreationUtils"; import { getOrganizationRepository } from "@calcom/features/ee/organizations/di/OrganizationRepository.container"; +import { findUserToBeOrgOwner } from "@calcom/features/ee/organizations/lib/server/orgCreationUtils"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import { IS_SELF_HOSTED } from "@calcom/lib/constants"; import logger from "@calcom/lib/logger"; import { safeStringify } from "@calcom/lib/safeStringify"; import { getTranslation } from "@calcom/lib/server/i18n"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import type { Team, User } from "@calcom/prisma/client"; import { orgOnboardingInvitedMembersSchema, orgOnboardingTeamsSchema } from "@calcom/prisma/zod-utils"; diff --git a/packages/features/ee/organizations/lib/service/onboarding/SelfHostedOnboardingService.ts b/packages/features/ee/organizations/lib/service/onboarding/SelfHostedOnboardingService.ts index d87bcf822b..472d2cf4c7 100644 --- a/packages/features/ee/organizations/lib/service/onboarding/SelfHostedOnboardingService.ts +++ b/packages/features/ee/organizations/lib/service/onboarding/SelfHostedOnboardingService.ts @@ -1,12 +1,12 @@ import { LicenseKeySingleton } from "@calcom/ee/common/server/LicenseKeyService"; -import { findUserToBeOrgOwner } from "@calcom/features/ee/organizations/lib/server/orgCreationUtils"; import { getOrganizationRepository } from "@calcom/features/ee/organizations/di/OrganizationRepository.container"; +import { findUserToBeOrgOwner } from "@calcom/features/ee/organizations/lib/server/orgCreationUtils"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import { IS_SELF_HOSTED } from "@calcom/lib/constants"; import logger from "@calcom/lib/logger"; import { safeStringify } from "@calcom/lib/safeStringify"; import { getTranslation } from "@calcom/lib/server/i18n"; import { DeploymentRepository } from "@calcom/lib/server/repository/deployment"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import { prisma } from "@calcom/prisma"; import type { Team, User } from "@calcom/prisma/client"; import { BillingPeriod } from "@calcom/prisma/enums"; @@ -28,7 +28,7 @@ const teamsSchema = orgOnboardingTeamsSchema; /** * Handles organization onboarding when billing is disabled (self-hosted admin flow). * -* Flow: + * Flow: * 1. Create onboarding record * 2. Store teams/invites in database * 3. Immediately create organization, teams, and invite members diff --git a/packages/features/ee/organizations/lib/service/onboarding/__tests__/SelfHostedOnboardingService.test.ts b/packages/features/ee/organizations/lib/service/onboarding/__tests__/SelfHostedOnboardingService.test.ts index 84bad8b010..fef7ede407 100644 --- a/packages/features/ee/organizations/lib/service/onboarding/__tests__/SelfHostedOnboardingService.test.ts +++ b/packages/features/ee/organizations/lib/service/onboarding/__tests__/SelfHostedOnboardingService.test.ts @@ -3,8 +3,8 @@ import prismock from "../../../../../../../../tests/libs/__mocks__/prisma"; import { describe, expect, it, vi, beforeEach } from "vitest"; import { LicenseKeySingleton } from "@calcom/ee/common/server/LicenseKeyService"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import * as constants from "@calcom/lib/constants"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import { UserPermissionRole, CreationSource, MembershipRole, BillingPeriod } from "@calcom/prisma/enums"; import { createTeamsHandler } from "@calcom/trpc/server/routers/viewer/organizations/createTeams.handler"; import { inviteMembersWithNoInviterPermissionCheck } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler"; @@ -13,7 +13,7 @@ import { SelfHostedOrganizationOnboardingService } from "../SelfHostedOnboarding import type { CreateOnboardingIntentInput, OrganizationOnboardingData } from "../types"; vi.mock("../../OrganizationPaymentService"); -vi.mock("@calcom/lib/server/repository/organizationOnboarding"); +vi.mock("@calcom/features/organizations/repositories/OrganizationOnboardingRepository"); vi.mock("@calcom/ee/common/server/LicenseKeyService", () => ({ LicenseKeySingleton: { getInstance: vi.fn(), diff --git a/packages/lib/server/repository/organizationOnboarding.ts b/packages/features/organizations/repositories/OrganizationOnboardingRepository.ts similarity index 100% rename from packages/lib/server/repository/organizationOnboarding.ts rename to packages/features/organizations/repositories/OrganizationOnboardingRepository.ts diff --git a/packages/trpc/server/routers/viewer/organizations/createSelfHosted.handler.ts b/packages/trpc/server/routers/viewer/organizations/createSelfHosted.handler.ts index 6a3b418be6..6e43cc61bf 100644 --- a/packages/trpc/server/routers/viewer/organizations/createSelfHosted.handler.ts +++ b/packages/trpc/server/routers/viewer/organizations/createSelfHosted.handler.ts @@ -1,6 +1,6 @@ import { SelfHostedOrganizationOnboardingService } from "@calcom/features/ee/organizations/lib/service/onboarding/SelfHostedOnboardingService"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import { IS_SELF_HOSTED } from "@calcom/lib/constants"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import { TRPCError } from "@trpc/server"; diff --git a/packages/trpc/server/routers/viewer/organizations/createWithPaymentIntent.handler.ts b/packages/trpc/server/routers/viewer/organizations/createWithPaymentIntent.handler.ts index 03303d271a..f9a3b29464 100644 --- a/packages/trpc/server/routers/viewer/organizations/createWithPaymentIntent.handler.ts +++ b/packages/trpc/server/routers/viewer/organizations/createWithPaymentIntent.handler.ts @@ -8,9 +8,9 @@ * - The new endpoint returns checkoutUrl directly in the response */ import { OrganizationPaymentService } from "@calcom/features/ee/organizations/lib/OrganizationPaymentService"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import logger from "@calcom/lib/logger"; import { safeStringify } from "@calcom/lib/safeStringify"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import { TRPCError } from "@trpc/server"; diff --git a/packages/trpc/server/routers/viewer/organizations/getOrganizationOnboarding.handler.ts b/packages/trpc/server/routers/viewer/organizations/getOrganizationOnboarding.handler.ts index 0f332e4119..1a91ccf900 100644 --- a/packages/trpc/server/routers/viewer/organizations/getOrganizationOnboarding.handler.ts +++ b/packages/trpc/server/routers/viewer/organizations/getOrganizationOnboarding.handler.ts @@ -1,4 +1,4 @@ -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import type { TrpcSessionUser } from "../../../types"; diff --git a/packages/trpc/server/routers/viewer/organizations/intentToCreateOrg.handler.ts b/packages/trpc/server/routers/viewer/organizations/intentToCreateOrg.handler.ts index 50ac1a837f..1d22e695d2 100644 --- a/packages/trpc/server/routers/viewer/organizations/intentToCreateOrg.handler.ts +++ b/packages/trpc/server/routers/viewer/organizations/intentToCreateOrg.handler.ts @@ -4,11 +4,11 @@ import { assertCanCreateOrg, findUserToBeOrgOwner, } from "@calcom/features/ee/organizations/lib/server/orgCreationUtils"; +import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository"; import { IS_SELF_HOSTED } from "@calcom/lib/constants"; import logger from "@calcom/lib/logger"; import { safeStringify } from "@calcom/lib/safeStringify"; import { DeploymentRepository } from "@calcom/lib/server/repository/deployment"; -import { OrganizationOnboardingRepository } from "@calcom/lib/server/repository/organizationOnboarding"; import { prisma } from "@calcom/prisma"; import { UserPermissionRole } from "@calcom/prisma/enums";