refactor: replace FeaturesRepository with DI-based feature repositories (#27200)

* refactor: replace FeaturesRepository with DI-based feature repositories

Migrate from the legacy FeaturesRepository pattern to separate DI-based repositories:
- Add checkIfFeatureIsEnabledGlobally to IFeatureRepository
- Add getTeamsWithFeatureEnabled to ITeamFeatureRepository
- Update CalendarSubscriptionService to use featureRepository, teamFeatureRepository, and userFeatureRepository
- Update SelectedCalendarRepository.findNextSubscriptionBatch to filter by teamIds instead of featureIds
- Update OnboardingPathService to use DI via getFeatureRepository()
- Remove prisma parameter from OnboardingPathService callsites

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* test: update tests to use new DI-based feature repositories

Update CalendarSubscriptionService and SelectedCalendarRepository tests
to use the new separate repository interfaces:
- featureRepository for global feature checks
- teamFeatureRepository for team-level feature checks
- userFeatureRepository for user-level feature checks

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* fix: update API routes to use DI-based feature repositories

Update cron and webhook routes to use the new separate repository
interfaces instead of the combined FeaturesRepository.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* fix: remove prisma arg from getGettingStartedPathWithParams call

The OnboardingPathService method no longer requires a prisma argument
as it now uses DI containers internally.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* test: update route tests to expect new DI-based feature repositories

Update service instantiation tests to expect featureRepository,
teamFeatureRepository, and userFeatureRepository instead of the
old featuresRepository.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* fix: optimize global feature check and add guard in checkForNewSubscriptions

- Use targeted select for only `enabled` field in checkIfFeatureIsEnabledGlobally
- Add global feature flag guard in checkForNewSubscriptions to avoid unnecessary
  DB queries and API calls when the cache feature is globally disabled

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* remove redundant comment

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
This commit is contained in:
Eunjae LeeandClaude Opus 4.5 authored and GitHub committed 2026-02-06 09:34:03 +00:00
1 parent cb36fc201f
commit 512002aaef
21 files changed
+265 -285

No files matched your search

@@ -24,7 +24,6 @@ import { MembershipRole } from "@calcom/prisma/enums";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
import { TRPCError } from "@trpc/server";
import type { TFunction } from "i18next";
import { isEmail } from "../util";
import type { TeamWithParent } from "./types";
@@ -541,7 +540,7 @@ export async function sendSignupToOrganizationEmail({
}) {
try {
const verificationToken = await createVerificationToken(usernameOrEmail, teamId);
const gettingStartedPath = await OnboardingPathService.getGettingStartedPathWhenInvited(prisma);
const gettingStartedPath = await OnboardingPathService.getGettingStartedPathWhenInvited();
await sendTeamInviteEmail({
language: translation,
from: inviterName || `${team.name}'s admin`,
@@ -758,7 +757,7 @@ export const sendExistingUserTeamInviteEmails = async ({
if (!user.completedOnboarding && !user.password?.hash && user.identityProvider === "CAL") {
const verificationToken = await createVerificationToken(user.email, teamId);
const gettingStartedPath = await OnboardingPathService.getGettingStartedPathWhenInvited(prisma);
const gettingStartedPath = await OnboardingPathService.getGettingStartedPathWhenInvited();
inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${verificationToken.token}&callbackUrl=${gettingStartedPath}`;
inviteTeamOptions.isCalcomMember = false;
} else if (!isAutoJoin) {
@@ -1,12 +1,11 @@
import { sendTeamInviteEmail } from "@calcom/emails/organization-email-service";
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
import { OnboardingPathService } from "@calcom/features/onboarding/lib/onboarding-path.service";
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { getTranslation } from "@calcom/lib/server/i18n";
import { VerificationTokenRepository } from "@calcom/lib/server/repository/verificationToken";
import { prisma } from "@calcom/prisma";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
import { ensureAtleastAdminPermissions, getTeamOrThrow } from "./inviteMember/utils";
import type { TResendInvitationInputSchema } from "./resendInvitation.schema";
@@ -27,7 +26,9 @@ export const resendInvitationHandler = async ({ ctx, input }: InviteMemberOption
isOrg: input.isOrg,
});
let verificationToken: Awaited<ReturnType<typeof VerificationTokenRepository.updateTeamInviteTokenExpirationDate>> | undefined;
let verificationToken:
| Awaited<ReturnType<typeof VerificationTokenRepository.updateTeamInviteTokenExpirationDate>>
| undefined;
try {
verificationToken = await VerificationTokenRepository.updateTeamInviteTokenExpirationDate({
@@ -52,7 +53,7 @@ export const resendInvitationHandler = async ({ ctx, input }: InviteMemberOption
if (user?.completedOnboarding) {
inviteTeamOptions.joinLink = `${WEBAPP_URL}/teams?token=${verificationToken.token}&autoAccept=true`;
} else {
const gettingStartedPath = await OnboardingPathService.getGettingStartedPathWhenInvited(prisma);
const gettingStartedPath = await OnboardingPathService.getGettingStartedPathWhenInvited();
inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${verificationToken.token}&callbackUrl=${gettingStartedPath}`;
inviteTeamOptions.isCalcomMember = false;
}