The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix cleaning command (#17040)
Etiennef3d89ca9b98e
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.tsindex 63f3e07723a..8844c6e70e4 100644--- a/packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.ts+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.ts@@ -70,25 +70,36 @@ export class CleanerWorkspaceService {);}- async computeWorkspaceBillingInactivity(+ async computeDaysSinceSubscriptionUnpaidOrThrow(workspace: WorkspaceEntity,): Promise<number> {try {const lastSubscription =await this.billingSubscriptionRepository.findOneOrFail({- where: { workspaceId: workspace.id },+ where: {+ workspaceId: workspace.id,+ },order: { updatedAt: 'DESC' },});- const daysSinceBillingInactivity = differenceInDays(+ if (+ lastSubscription.status !== SubscriptionStatus.Unpaid &&+ lastSubscription.status !== SubscriptionStatus.Canceled+ ) {+ throw new Error(+ 'No cancelled or unpaid billing subscription found for workspace',+ );+ }++ const daysSinceSubscriptionUnpaid = differenceInDays(new Date(),- lastSubscription.updatedAt,+ lastSubscription.currentPeriodStart,);- return daysSinceBillingInactivity;+ return daysSinceSubscriptionUnpaid;} catch {throw new WorkspaceCleanerException(- `No billing subscription found for workspace ${workspace.id} ${workspace.displayName}`,+ `No cancelled or unpaid billing subscription found for workspace ${workspace.id} ${workspace.displayName}`,WorkspaceCleanerExceptionCode.BILLING_SUBSCRIPTION_NOT_FOUND,);}@@ -374,7 +385,7 @@ export class CleanerWorkspaceService {}const workspaceInactivity =- await this.computeWorkspaceBillingInactivity(workspace);+ await this.computeDaysSinceSubscriptionUnpaidOrThrow(workspace);if (workspaceInactivity > this.inactiveDaysBeforeSoftDelete) {await this.informWorkspaceMembersAndSoftDeleteWorkspace(