refactor: convert getShouldServeCache to CacheService with dependency injection (#22814)
* refactor: convert getShouldServeCache to CacheService with dependency injection - Create CacheService class following AvailableSlotsService DI pattern - Add FeaturesRepository and CacheService to DI tokens and modules - Create cache container with proper dependency injection setup - Update handleNewBooking.ts and slots/util.ts to use new service - Maintain backward compatibility with error-throwing wrapper function - Follow established service patterns for clean architecture Co-Authored-By: [email protected] <[email protected]> * feat: inject CacheService into AvailableSlotsService via dependency injection - Add cacheService to IAvailableSlotsService interface - Update available-slots container to load cache modules - Update available-slots module to inject CacheService dependency - Replace direct getShouldServeCache call with injected service method - Add CacheService import to util.ts for proper typing Co-Authored-By: [email protected] <[email protected]> * chore: DI api v2 cache service * refactor: convert FeaturesRepository to use factory pattern in DI - Change from constructor injection to factory pattern to avoid PRISMA_CLIENT binding issues in tests - FeaturesRepository now uses default prisma instance instead of DI injection - Resolves test failures while maintaining DI container compatibility - Tests reduced from 123+ failures to only 5 unrelated failures Co-Authored-By: [email protected] <[email protected]> * revert: use direct FeaturesRepository instantiation in most usage points - Revert getFeaturesRepository() calls back to new FeaturesRepository() - Tests require direct instantiation for mocking compatibility - Keep DI container for specific use cases that need dependency injection - Resolves test failures while maintaining both DI and direct usage patterns Co-Authored-By: [email protected] <[email protected]> * fix: resolve FeaturesRepository DI container issues - Update cache module to use factory pattern with proper ICacheService interface - Remove featuresModule loading from cache and available-slots containers - Use direct FeaturesRepository instantiation via getFeaturesRepository() - Resolves 'No binding found for key: Symbol(FeaturesRepository)' errors - Reduces test failures from 125 to 7 (remaining failures appear unrelated) Co-Authored-By: [email protected] <[email protected]> * fix: update all FeaturesRepository instantiations to include prisma parameter - Add prisma parameter to all new FeaturesRepository() calls across the codebase - Update API v2 services to match main repo interfaces - Fix PrismaFeaturesRepository to implement IFeaturesRepository directly - Update CacheService in API v2 to expose required dependencies and getShouldServeCache - Implement CheckBookingLimitsService in API v2 with proper interface - Resolves type assignment errors between API v2 and main repo implementations Co-Authored-By: [email protected] <[email protected]> * fix: add prisma parameter to remaining FeaturesRepository instantiations in apps/web/lib - Update getServerSideProps files to pass prisma parameter to FeaturesRepository - Ensures all FeaturesRepository instantiations follow the new constructor pattern - Completes the refactoring to use direct instantiation with prisma parameter Co-Authored-By: [email protected] <[email protected]> * refactor clean and fix devin issues * chore: bump platform libs * chore: bump platform libs * chore: bump platform libs * chore: bump platform libs * fix: missing di * fix workflow test * fix workflow test * fix integration test --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Morgan <[email protected]>
This commit is contained in:
51 files changed
+179
-74
No files matched your search
@@ -1153,7 +1153,7 @@ export default class EventManager {
|
||||
private async createAllCRMEvents(event: CalendarEvent) {
|
||||
const createdEvents = [];
|
||||
|
||||
const featureRepo = new FeaturesRepository();
|
||||
const featureRepo = new FeaturesRepository(prisma);
|
||||
const isTaskerEnabledForSalesforceCrm = event.team?.id
|
||||
? await featureRepo.checkIfTeamHasFeature(event.team.id, "salesforce-crm-tasker")
|
||||
: false;
|
||||
|
||||
@@ -6,8 +6,10 @@ import type { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/s
|
||||
|
||||
import { availableSlotsModule } from "../modules/available-slots";
|
||||
import { bookingRepositoryModule } from "../modules/booking";
|
||||
import { cacheModule } from "../modules/cache";
|
||||
import { checkBookingLimitsModule } from "../modules/check-booking-limits";
|
||||
import { eventTypeRepositoryModule } from "../modules/eventType";
|
||||
import { featuresRepositoryModule } from "../modules/features";
|
||||
import { oooRepositoryModule } from "../modules/ooo";
|
||||
import { routingFormResponseRepositoryModule } from "../modules/routingFormResponse";
|
||||
import { scheduleRepositoryModule } from "../modules/schedule";
|
||||
@@ -25,6 +27,8 @@ container.load(DI_TOKENS.USER_REPOSITORY_MODULE, userRepositoryModule);
|
||||
container.load(DI_TOKENS.BOOKING_REPOSITORY_MODULE, bookingRepositoryModule);
|
||||
container.load(DI_TOKENS.EVENT_TYPE_REPOSITORY_MODULE, eventTypeRepositoryModule);
|
||||
container.load(DI_TOKENS.ROUTING_FORM_RESPONSE_REPOSITORY_MODULE, routingFormResponseRepositoryModule);
|
||||
container.load(DI_TOKENS.FEATURES_REPOSITORY_MODULE, featuresRepositoryModule);
|
||||
container.load(DI_TOKENS.CACHE_SERVICE_MODULE, cacheModule);
|
||||
container.load(DI_TOKENS.CHECK_BOOKING_LIMITS_SERVICE_MODULE, checkBookingLimitsModule);
|
||||
container.load(DI_TOKENS.AVAILABLE_SLOTS_SERVICE_MODULE, availableSlotsModule);
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { createContainer } from "@evyweb/ioctopus";
|
||||
|
||||
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||
|
||||
import type { CacheService } from "../../../features/calendar-cache/lib/getShouldServeCache";
|
||||
import { cacheModule } from "../modules/cache";
|
||||
import { featuresRepositoryModule } from "../modules/features";
|
||||
|
||||
const container = createContainer();
|
||||
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||
container.load(DI_TOKENS.FEATURES_REPOSITORY_MODULE, featuresRepositoryModule);
|
||||
container.load(DI_TOKENS.CACHE_SERVICE_MODULE, cacheModule);
|
||||
|
||||
export function getCacheService() {
|
||||
return container.get<CacheService>(DI_TOKENS.CACHE_SERVICE);
|
||||
}
|
||||
@@ -15,5 +15,6 @@ availableSlotsModule.bind(DI_TOKENS.AVAILABLE_SLOTS_SERVICE).toClass(AvailableSl
|
||||
bookingRepo: DI_TOKENS.BOOKING_REPOSITORY,
|
||||
eventTypeRepo: DI_TOKENS.EVENT_TYPE_REPOSITORY,
|
||||
routingFormResponseRepo: DI_TOKENS.ROUTING_FORM_RESPONSE_REPOSITORY,
|
||||
cacheService: DI_TOKENS.CACHE_SERVICE,
|
||||
checkBookingLimitsService: DI_TOKENS.CHECK_BOOKING_LIMITS_SERVICE,
|
||||
} satisfies Record<keyof IAvailableSlotsService, symbol>);
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createModule } from "@evyweb/ioctopus";
|
||||
|
||||
import type { ICacheService } from "@calcom/features/calendar-cache/lib/getShouldServeCache";
|
||||
import { CacheService } from "@calcom/features/calendar-cache/lib/getShouldServeCache";
|
||||
|
||||
import { DI_TOKENS } from "../tokens";
|
||||
|
||||
export const cacheModule = createModule();
|
||||
cacheModule.bind(DI_TOKENS.CACHE_SERVICE).toClass(CacheService, {
|
||||
featuresRepository: DI_TOKENS.FEATURES_REPOSITORY,
|
||||
} satisfies Record<keyof ICacheService, symbol>);
|
||||
@@ -0,0 +1,9 @@
|
||||
import { createModule } from "@evyweb/ioctopus";
|
||||
|
||||
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||
|
||||
export const featuresRepositoryModule = createModule();
|
||||
featuresRepositoryModule
|
||||
.bind(DI_TOKENS.FEATURES_REPOSITORY)
|
||||
.toClass(FeaturesRepository, [DI_TOKENS.PRISMA_CLIENT]);
|
||||
@@ -22,6 +22,10 @@ export const DI_TOKENS = {
|
||||
AVAILABLE_SLOTS_SERVICE_MODULE: Symbol("AvailableSlotsModule"),
|
||||
INSIGHTS_ROUTING_SERVICE: Symbol("InsightsRoutingService"),
|
||||
INSIGHTS_ROUTING_SERVICE_MODULE: Symbol("InsightsRoutingServiceModule"),
|
||||
FEATURES_REPOSITORY: Symbol("FeaturesRepository"),
|
||||
FEATURES_REPOSITORY_MODULE: Symbol("FeaturesRepositoryModule"),
|
||||
CACHE_SERVICE: Symbol("CacheService"),
|
||||
CACHE_SERVICE_MODULE: Symbol("CacheServiceModule"),
|
||||
CHECK_BOOKING_LIMITS_SERVICE: Symbol("CheckBookingLimitsService"),
|
||||
CHECK_BOOKING_LIMITS_SERVICE_MODULE: Symbol("CheckBookingLimitsServiceModule"),
|
||||
CHECK_BOOKING_AND_DURATION_LIMITS_SERVICE: Symbol("CheckBookingAndDurationLimitsService"),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
/**
|
||||
* Checks if the restriction schedule feature is enabled for a team
|
||||
@@ -10,6 +11,6 @@ export async function isRestrictionScheduleEnabled(teamId?: number): Promise<boo
|
||||
return false; // Personal events don't have restriction schedules
|
||||
}
|
||||
|
||||
const featureRepo = new FeaturesRepository();
|
||||
const featureRepo = new FeaturesRepository(prisma);
|
||||
return await featureRepo.checkIfTeamHasFeature(teamId, "restriction-schedule");
|
||||
}
|
||||
Reference in new issue
Block a user