Skip to content

The open alternative to Salesforce, designed for AI.

Fix broken workspace deletion (#9002)

Félix Malfait0a8960c2eda9
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 20fe027db52..7dcaeab7fdd 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<Workspace> {
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<Workspace> {
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);