@@ -7,19 +7,11 @@ import { Command, CommandRunner, Option } from 'nest-commander';
7
7
import { Repository } from 'typeorm' ;
8
8
9
9
import { TypeORMService } from 'src/database/typeorm/typeorm.service' ;
10
- import {
11
- BillingSubscription ,
12
- SubscriptionStatus ,
13
- } from 'src/engine/core-modules/billing/entities/billing-subscription.entity' ;
14
- import {
15
- FeatureFlagEntity ,
16
- FeatureFlagKeys ,
17
- } from 'src/engine/core-modules/feature-flag/feature-flag.entity' ;
18
- import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity' ;
19
10
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service' ;
20
11
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity' ;
21
12
import { WorkspaceCacheVersionService } from 'src/engine/metadata-modules/workspace-cache-version/workspace-cache-version.service' ;
22
13
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager' ;
14
+ import { WorkspaceStatusService } from 'src/engine/workspace-manager/workspace-status/services/workspace-status.service' ;
23
15
import { COMPANY_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids' ;
24
16
import { ViewFieldWorkspaceEntity } from 'src/modules/view/standard-objects/view-field.workspace-entity' ;
25
17
@@ -36,18 +28,13 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
36
28
AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand . name ,
37
29
) ;
38
30
constructor (
39
- @InjectRepository ( Workspace , 'core' )
40
- private readonly workspaceRepository : Repository < Workspace > ,
41
- @InjectRepository ( BillingSubscription , 'core' )
42
- private readonly billingSubscriptionRepository : Repository < BillingSubscription > ,
43
- @InjectRepository ( FeatureFlagEntity , 'core' )
44
- private readonly featureFlagRepository : Repository < FeatureFlagEntity > ,
45
31
@InjectRepository ( FieldMetadataEntity , 'metadata' )
46
32
private readonly fieldMetadataRepository : Repository < FieldMetadataEntity > ,
47
33
private readonly typeORMService : TypeORMService ,
48
34
private readonly dataSourceService : DataSourceService ,
49
35
private readonly workspaceCacheVersionService : WorkspaceCacheVersionService ,
50
36
private readonly twentyORMManager : TwentyORMManager ,
37
+ private readonly workspaceStatusService : WorkspaceStatusService ,
51
38
) {
52
39
super ( ) ;
53
40
}
@@ -76,19 +63,8 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
76
63
if ( options . workspaceId ) {
77
64
workspaceIds = [ options . workspaceId ] ;
78
65
} else {
79
- const workspaces = await this . workspaceRepository . find ( ) ;
80
-
81
- const activeWorkspaceIds = (
82
- await Promise . all (
83
- workspaces . map ( async ( workspace ) => {
84
- const isActive = await this . workspaceIsActive ( workspace ) ;
85
-
86
- return { workspace, isActive } ;
87
- } ) ,
88
- )
89
- )
90
- . filter ( ( result ) => result . isActive )
91
- . map ( ( result ) => result . workspace . id ) ;
66
+ const activeWorkspaceIds =
67
+ await this . workspaceStatusService . getActiveWorkspaceIds ( ) ;
92
68
93
69
workspaceIds = activeWorkspaceIds ;
94
70
}
@@ -198,33 +174,4 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
198
174
199
175
this . logger . log ( chalk . green ( `Command completed!` ) ) ;
200
176
}
201
-
202
- private async workspaceIsActive ( workspace : Workspace ) : Promise < boolean > {
203
- const billingSupscriptionForWorkspace =
204
- await this . billingSubscriptionRepository . findOne ( {
205
- where : { workspaceId : workspace . id } ,
206
- } ) ;
207
-
208
- if (
209
- billingSupscriptionForWorkspace ?. status &&
210
- [
211
- SubscriptionStatus . PastDue ,
212
- SubscriptionStatus . Active ,
213
- SubscriptionStatus . Trialing ,
214
- ] . includes ( billingSupscriptionForWorkspace . status as SubscriptionStatus )
215
- ) {
216
- return true ;
217
- }
218
-
219
- const freeAccessEnabledFeatureFlagForWorkspace =
220
- await this . featureFlagRepository . findOne ( {
221
- where : {
222
- workspaceId : workspace . id ,
223
- key : FeatureFlagKeys . IsFreeAccessEnabled ,
224
- value : true ,
225
- } ,
226
- } ) ;
227
-
228
- return ! ! freeAccessEnabledFeatureFlagForWorkspace ;
229
- }
230
177
}
0 commit comments