From a8990caea728494360dcd27e068a499c2357b03e Mon Sep 17 00:00:00 2001 From: kwasniew Date: Thu, 26 Sep 2024 14:15:34 +0200 Subject: [PATCH 1/2] refactor: composition root for personal dashboard service --- src/lib/features/index.ts | 1 + .../createPersonalDashboardService.ts | 29 +++++++++++++++++++ src/lib/services/index.ts | 24 +++++---------- 3 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 src/lib/features/personal-dashboard/createPersonalDashboardService.ts diff --git a/src/lib/features/index.ts b/src/lib/features/index.ts index eb12dddd9a09..5ca09cf4b1c0 100644 --- a/src/lib/features/index.ts +++ b/src/lib/features/index.ts @@ -11,3 +11,4 @@ export * from './events/createEventsService'; export * from './instance-stats/createInstanceStatsService'; export * from './feature-lifecycle/createFeatureLifecycle'; export * from './playground/createPlaygroundService'; +export * from './personal-dashboard/createPersonalDashboardService'; diff --git a/src/lib/features/personal-dashboard/createPersonalDashboardService.ts b/src/lib/features/personal-dashboard/createPersonalDashboardService.ts new file mode 100644 index 000000000000..cb88ef82ac34 --- /dev/null +++ b/src/lib/features/personal-dashboard/createPersonalDashboardService.ts @@ -0,0 +1,29 @@ +import type { Db } from '../../db/db'; +import type { IUnleashConfig } from '../../types'; +import { PersonalDashboardService } from './personal-dashboard-service'; +import { PersonalDashboardReadModel } from './personal-dashboard-read-model'; +import { FakePersonalDashboardReadModel } from './fake-personal-dashboard-read-model'; +import { ProjectOwnersReadModel } from '../project/project-owners-read-model'; +import { FakeProjectOwnersReadModel } from '../project/fake-project-owners-read-model'; +import { ProjectReadModel } from '../project/project-read-model'; +import { FakeProjectReadModel } from '../project/fake-project-read-model'; + +export const createPersonalDashboardService = ( + db: Db, + config: IUnleashConfig, +) => { + return new PersonalDashboardService( + new PersonalDashboardReadModel(db), + + new ProjectOwnersReadModel(db), + new ProjectReadModel(db, config.eventBus, config.flagResolver), + ); +}; + +export const createFakePersonalDashboardService = () => { + return new PersonalDashboardService( + new FakePersonalDashboardReadModel(), + new FakeProjectOwnersReadModel(), + new FakeProjectReadModel(), + ); +}; diff --git a/src/lib/services/index.ts b/src/lib/services/index.ts index 1f8a8be26668..7a76de191a62 100644 --- a/src/lib/services/index.ts +++ b/src/lib/services/index.ts @@ -147,12 +147,10 @@ import { } from '../features/onboarding/createOnboardingService'; import { OnboardingService } from '../features/onboarding/onboarding-service'; import { PersonalDashboardService } from '../features/personal-dashboard/personal-dashboard-service'; -import { PersonalDashboardReadModel } from '../features/personal-dashboard/personal-dashboard-read-model'; -import { FakePersonalDashboardReadModel } from '../features/personal-dashboard/fake-personal-dashboard-read-model'; -import { ProjectOwnersReadModel } from '../features/project/project-owners-read-model'; -import { FakeProjectOwnersReadModel } from '../features/project/fake-project-owners-read-model'; -import { FakeProjectReadModel } from '../features/project/fake-project-read-model'; -import { ProjectReadModel } from '../features/project/project-read-model'; +import { + createFakePersonalDashboardService, + createPersonalDashboardService, +} from '../features/personal-dashboard/createPersonalDashboardService'; export const createServices = ( stores: IUnleashStores, @@ -408,17 +406,9 @@ export const createServices = ( : createFakeOnboardingService(config).onboardingService; onboardingService.listen(); - // TODO: move to composition root - const personalDashboardService = new PersonalDashboardService( - db - ? new PersonalDashboardReadModel(db) - : new FakePersonalDashboardReadModel(), - - db ? new ProjectOwnersReadModel(db) : new FakeProjectOwnersReadModel(), - db - ? new ProjectReadModel(db, config.eventBus, config.flagResolver) - : new FakeProjectReadModel(), - ); + const personalDashboardService = db + ? createPersonalDashboardService(db, config) + : createFakePersonalDashboardService(); return { accessService, From ecfbeef2e8a8563db1acd6be47adbeefdbb021c4 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Thu, 26 Sep 2024 14:16:48 +0200 Subject: [PATCH 2/2] refactor: composition root for personal dashboard service --- .../personal-dashboard/createPersonalDashboardService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/features/personal-dashboard/createPersonalDashboardService.ts b/src/lib/features/personal-dashboard/createPersonalDashboardService.ts index cb88ef82ac34..1de2f55570ef 100644 --- a/src/lib/features/personal-dashboard/createPersonalDashboardService.ts +++ b/src/lib/features/personal-dashboard/createPersonalDashboardService.ts @@ -14,7 +14,6 @@ export const createPersonalDashboardService = ( ) => { return new PersonalDashboardService( new PersonalDashboardReadModel(db), - new ProjectOwnersReadModel(db), new ProjectReadModel(db, config.eventBus, config.flagResolver), );