From 0a8960c2eda9c43cfeafe74b9320e024755fdce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Malfait?= Date: Tue, 10 Dec 2024 14:13:58 +0100 Subject: [PATCH] Fix broken workspace deletion (#9002) Fixes #8985 --- .../workspace/services/workspace.service.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts b/packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts index 20fe027db..7dcaeab7f 100644 --- a/packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts +++ b/packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts @@ -7,6 +7,8 @@ import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm'; import { Repository } from 'typeorm'; import { BillingSubscriptionService } from 'src/engine/core-modules/billing/services/billing-subscription.service'; +import { BillingService } from 'src/engine/core-modules/billing/services/billing.service'; +import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service'; import { FeatureFlagService } from 'src/engine/core-modules/feature-flag/services/feature-flag.service'; import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity'; import { UserWorkspaceService } from 'src/engine/core-modules/user-workspace/user-workspace.service'; @@ -16,14 +18,13 @@ import { Workspace, WorkspaceActivationStatus, } from 'src/engine/core-modules/workspace/workspace.entity'; -import { WorkspaceManagerService } from 'src/engine/workspace-manager/workspace-manager.service'; -import { DEFAULT_FEATURE_FLAGS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/default-feature-flags'; import { WorkspaceException, WorkspaceExceptionCode, } from 'src/engine/core-modules/workspace/workspace.exception'; import { workspaceValidator } from 'src/engine/core-modules/workspace/workspace.validate'; -import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service'; +import { WorkspaceManagerService } from 'src/engine/workspace-manager/workspace-manager.service'; +import { DEFAULT_FEATURE_FLAGS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/default-feature-flags'; @Injectable() // eslint-disable-next-line @nx/workspace-inject-workspace-repository @@ -38,6 +39,7 @@ export class WorkspaceService extends TypeOrmQueryService { private readonly workspaceManagerService: WorkspaceManagerService, private readonly featureFlagService: FeatureFlagService, private readonly billingSubscriptionService: BillingSubscriptionService, + private readonly billingService: BillingService, private readonly userWorkspaceService: UserWorkspaceService, private readonly environmentService: EnvironmentService, ) { @@ -137,7 +139,10 @@ export class WorkspaceService extends TypeOrmQueryService { assert(workspace, 'Workspace not found'); await this.userWorkspaceRepository.delete({ workspaceId: id }); - await this.billingSubscriptionService.deleteSubscription(workspace.id); + + if (this.billingService.isBillingEnabled()) { + await this.billingSubscriptionService.deleteSubscription(workspace.id); + } await this.workspaceManagerService.delete(id);