From b5a2befec79b4dbc8cec25f8d5bd99a0bd675dcd Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Tue, 5 Nov 2024 11:52:15 +0100 Subject: [PATCH] feat: export transactional user subscriptions service (#8651) --- src/lib/features/index.ts | 1 + .../createUserSubscriptionsService.ts | 12 +++++++----- .../user-subscriptions-service.e2e.test.ts | 4 ++-- .../user-subscriptions/user-subscriptions-service.ts | 2 +- src/lib/services/index.ts | 9 +++++++++ src/lib/types/services.ts | 2 ++ 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/lib/features/index.ts b/src/lib/features/index.ts index 5ca09cf4b1c0..8ad9dfbb983c 100644 --- a/src/lib/features/index.ts +++ b/src/lib/features/index.ts @@ -12,3 +12,4 @@ export * from './instance-stats/createInstanceStatsService'; export * from './feature-lifecycle/createFeatureLifecycle'; export * from './playground/createPlaygroundService'; export * from './personal-dashboard/createPersonalDashboardService'; +export * from './user-subscriptions/createUserSubscriptionsService'; diff --git a/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts b/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts index b7dca58b6c40..e0a9d5b72254 100644 --- a/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts +++ b/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts @@ -1,5 +1,5 @@ import type { Db, IUnleashConfig } from '../../server-impl'; -import UserSubscriptionService from './user-subscriptions-service'; +import { UserSubscriptionsService } from './user-subscriptions-service'; import { UserUnsubscribeStore } from './user-unsubscribe-store'; import { createEventsService, @@ -9,11 +9,11 @@ import { FakeUserUnsubscribeStore } from './fake-user-unsubscribe-store'; export const createUserSubscriptionsService = (config: IUnleashConfig) => - (db: Db): UserSubscriptionService => { + (db: Db): UserSubscriptionsService => { const userUnsubscribeStore = new UserUnsubscribeStore(db); const eventService = createEventsService(db, config); - const userSubscriptionsService = new UserSubscriptionService( + const userSubscriptionsService = new UserSubscriptionsService( { userUnsubscribeStore }, config, eventService, @@ -22,11 +22,13 @@ export const createUserSubscriptionsService = return userSubscriptionsService; }; -export const createFakeUserSubscriptionsService = (config: IUnleashConfig) => { +export const createFakeUserSubscriptionsService = ( + config: IUnleashConfig, +): UserSubscriptionsService => { const userUnsubscribeStore = new FakeUserUnsubscribeStore(); const eventService = createFakeEventsService(config); - const userSubscriptionsService = new UserSubscriptionService( + const userSubscriptionsService = new UserSubscriptionsService( { userUnsubscribeStore }, config, eventService, diff --git a/src/lib/features/user-subscriptions/user-subscriptions-service.e2e.test.ts b/src/lib/features/user-subscriptions/user-subscriptions-service.e2e.test.ts index faf9bfff20db..39e5744a2ccd 100644 --- a/src/lib/features/user-subscriptions/user-subscriptions-service.e2e.test.ts +++ b/src/lib/features/user-subscriptions/user-subscriptions-service.e2e.test.ts @@ -4,7 +4,7 @@ import { type IUser, TEST_AUDIT_USER, } from '../../types'; -import type UserSubscriptionService from './user-subscriptions-service'; +import type { UserSubscriptionsService } from './user-subscriptions-service'; import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init'; import { createTestConfig } from '../../../test/config/test-config'; import getLogger from '../../../test/fixtures/no-logger'; @@ -13,7 +13,7 @@ import type { IUserSubscriptionsReadModel } from './user-subscriptions-read-mode let stores: IUnleashStores; let db: ITestDb; -let userSubscriptionService: UserSubscriptionService; +let userSubscriptionService: UserSubscriptionsService; let userSubscriptionsReadModel: IUserSubscriptionsReadModel; let config: IUnleashConfig; let user: IUser; diff --git a/src/lib/features/user-subscriptions/user-subscriptions-service.ts b/src/lib/features/user-subscriptions/user-subscriptions-service.ts index 3e197da2984e..cebd781a930b 100644 --- a/src/lib/features/user-subscriptions/user-subscriptions-service.ts +++ b/src/lib/features/user-subscriptions/user-subscriptions-service.ts @@ -7,7 +7,7 @@ import type { } from './user-unsubscribe-store-type'; import type EventService from '../events/event-service'; -export default class UserSubscriptionService { +export class UserSubscriptionsService { private userUnsubscribeStore: IUserUnsubscribeStore; private eventService: EventService; diff --git a/src/lib/services/index.ts b/src/lib/services/index.ts index b624b3070bb3..3015a22f76c5 100644 --- a/src/lib/services/index.ts +++ b/src/lib/services/index.ts @@ -70,9 +70,11 @@ import { createFakeEnvironmentService, createFakeEventsService, createFakeProjectService, + createFakeUserSubscriptionsService, createFeatureLifecycleService, createFeatureToggleService, createProjectService, + createUserSubscriptionsService, } from '../features'; import EventAnnouncerService from './event-announcer-service'; import { createGroupService } from '../features/group/createGroupService'; @@ -127,6 +129,7 @@ import { createProjectInsightsService, } from '../features/project-insights/createProjectInsightsService'; import { JobService } from '../features/scheduler/job-service'; +import { UserSubscriptionsService } from '../features/user-subscriptions/user-subscriptions-service'; import { JobStore } from '../features/scheduler/job-store'; import { FeatureLifecycleService } from '../features/feature-lifecycle/feature-lifecycle-service'; import { createFakeFeatureLifecycleService } from '../features/feature-lifecycle/createFeatureLifecycle'; @@ -426,6 +429,10 @@ export const createServices = ( ? createPersonalDashboardService(db, config, stores) : createFakePersonalDashboardService(config); + const transactionalUserSubscriptionsService = db + ? withTransactional(createUserSubscriptionsService(config), db) + : withFakeTransactional(createFakeUserSubscriptionsService(config)); + return { transactionalAccessService, accessService, @@ -492,6 +499,7 @@ export const createServices = ( onboardingService, personalDashboardService, projectStatusService, + transactionalUserSubscriptionsService, }; }; @@ -544,4 +552,5 @@ export { OnboardingService, PersonalDashboardService, ProjectStatusService, + UserSubscriptionsService, }; diff --git a/src/lib/types/services.ts b/src/lib/types/services.ts index e217abd570b8..3716314a377e 100644 --- a/src/lib/types/services.ts +++ b/src/lib/types/services.ts @@ -58,6 +58,7 @@ import type { IntegrationEventsService } from '../features/integration-events/in import type { OnboardingService } from '../features/onboarding/onboarding-service'; import type { PersonalDashboardService } from '../features/personal-dashboard/personal-dashboard-service'; import type { ProjectStatusService } from '../features/project-status/project-status-service'; +import type { UserSubscriptionsService } from '../features/user-subscriptions/user-subscriptions-service'; export interface IUnleashServices { transactionalAccessService: WithTransactional; @@ -128,4 +129,5 @@ export interface IUnleashServices { onboardingService: OnboardingService; personalDashboardService: PersonalDashboardService; projectStatusService: ProjectStatusService; + transactionalUserSubscriptionsService: WithTransactional; }