@@ -256,13 +256,27 @@ class FeatureToggleService {
256
256
}
257
257
}
258
258
259
- async validateNoChildren ( featureNames : string [ ] ) : Promise < void > {
259
+ async validateNoChildren ( featureName : string ) : Promise < void > {
260
260
if ( this . flagResolver . isEnabled ( 'dependentFeatures' ) ) {
261
- if ( featureNames . length === 0 ) return ;
262
- const children = await this . dependentFeaturesReadModel . getChildren (
263
- featureNames ,
264
- ) ;
261
+ const children = await this . dependentFeaturesReadModel . getChildren ( [
262
+ featureName ,
263
+ ] ) ;
265
264
if ( children . length > 0 ) {
265
+ throw new InvalidOperationError (
266
+ 'You can not archive/delete this feature since other features depend on it.' ,
267
+ ) ;
268
+ }
269
+ }
270
+ }
271
+
272
+ async validateNoOrphanParents ( featureNames : string [ ] ) : Promise < void > {
273
+ if ( this . flagResolver . isEnabled ( 'dependentFeatures' ) ) {
274
+ if ( featureNames . length === 0 ) return ;
275
+ const parents =
276
+ await this . dependentFeaturesReadModel . getOrphanParents (
277
+ featureNames ,
278
+ ) ;
279
+ if ( parents . length > 0 ) {
266
280
throw new InvalidOperationError (
267
281
featureNames . length > 1
268
282
? `You can not archive/delete those features since other features depend on them.`
@@ -1460,7 +1474,7 @@ class FeatureToggleService {
1460
1474
} ) ;
1461
1475
}
1462
1476
1463
- await this . validateNoChildren ( [ featureName ] ) ;
1477
+ await this . validateNoChildren ( featureName ) ;
1464
1478
1465
1479
await this . featureToggleStore . archive ( featureName ) ;
1466
1480
@@ -1479,7 +1493,7 @@ class FeatureToggleService {
1479
1493
projectId : string ,
1480
1494
) : Promise < void > {
1481
1495
await this . validateFeaturesContext ( featureNames , projectId ) ;
1482
- await this . validateNoChildren ( featureNames ) ;
1496
+ await this . validateNoOrphanParents ( featureNames ) ;
1483
1497
1484
1498
const features = await this . featureToggleStore . getAllByNames (
1485
1499
featureNames ,
@@ -1780,7 +1794,7 @@ class FeatureToggleService {
1780
1794
1781
1795
// TODO: add project id.
1782
1796
async deleteFeature ( featureName : string , createdBy : string ) : Promise < void > {
1783
- await this . validateNoChildren ( [ featureName ] ) ;
1797
+ await this . validateNoChildren ( featureName ) ;
1784
1798
const toggle = await this . featureToggleStore . get ( featureName ) ;
1785
1799
const tags = await this . tagStore . getAllTagsForFeature ( featureName ) ;
1786
1800
await this . featureToggleStore . delete ( featureName ) ;
@@ -1802,7 +1816,7 @@ class FeatureToggleService {
1802
1816
createdBy : string ,
1803
1817
) : Promise < void > {
1804
1818
await this . validateFeaturesContext ( featureNames , projectId ) ;
1805
- await this . validateNoChildren ( featureNames ) ;
1819
+ await this . validateNoOrphanParents ( featureNames ) ;
1806
1820
1807
1821
const features = await this . featureToggleStore . getAllByNames (
1808
1822
featureNames ,
0 commit comments