5
5
type IEnvironmentStore ,
6
6
type IFeatureEnvironmentStore ,
7
7
type IFeatureStrategiesStore ,
8
- type IProjectEnvironment ,
8
+ type IProjectsAvailableOnEnvironment ,
9
9
type ISortOrder ,
10
10
type IUnleashConfig ,
11
11
type IUnleashStores ,
@@ -19,7 +19,6 @@ import NameExistsError from '../../error/name-exists-error';
19
19
import { sortOrderSchema } from '../../services/sort-order-schema' ;
20
20
import NotFoundError from '../../error/notfound-error' ;
21
21
import type { IProjectStore } from '../../features/project/project-store-type' ;
22
- import MinimumOneEnvironmentError from '../../error/minimum-one-environment-error' ;
23
22
import type { IFlagResolver } from '../../types/experimental' ;
24
23
import type { CreateFeatureStrategySchema } from '../../openapi' ;
25
24
import type EventService from '../events/event-service' ;
@@ -77,8 +76,24 @@ export default class EnvironmentService {
77
76
78
77
async getProjectEnvironments (
79
78
projectId : string ,
80
- ) : Promise < IProjectEnvironment [ ] > {
81
- return this . environmentStore . getProjectEnvironments ( projectId ) ;
79
+ ) : Promise < IProjectsAvailableOnEnvironment [ ] > {
80
+ // This function produces an object for every environment, in that object is a boolean
81
+ // describing whether or not that environment is enabled - aka not deprecated
82
+ const environments =
83
+ await this . projectStore . getEnvironmentsForProject ( projectId ) ;
84
+ const environmentsOnProject = new Set (
85
+ environments . map ( ( env ) => env . environment ) ,
86
+ ) ;
87
+
88
+ const allEnvironments =
89
+ await this . environmentStore . getProjectEnvironments ( projectId ) ;
90
+
91
+ return allEnvironments . map ( ( env ) => {
92
+ return {
93
+ ...env ,
94
+ visible : environmentsOnProject . has ( env . name ) ,
95
+ } ;
96
+ } ) ;
82
97
}
83
98
84
99
async updateSortOrder ( sortOrder : ISortOrder ) : Promise < void > {
@@ -254,22 +269,13 @@ export default class EnvironmentService {
254
269
const projectEnvs =
255
270
await this . projectStore . getEnvironmentsForProject ( projectId ) ;
256
271
257
- if ( projectEnvs . length > 1 ) {
258
- await this . forceRemoveEnvironmentFromProject (
272
+ await this . forceRemoveEnvironmentFromProject ( environment , projectId ) ;
273
+ await this . eventService . storeEvent (
274
+ new ProjectEnvironmentRemoved ( {
275
+ project : projectId ,
259
276
environment,
260
- projectId ,
261
- ) ;
262
- await this . eventService . storeEvent (
263
- new ProjectEnvironmentRemoved ( {
264
- project : projectId ,
265
- environment,
266
- auditUser,
267
- } ) ,
268
- ) ;
269
- return ;
270
- }
271
- throw new MinimumOneEnvironmentError (
272
- 'You must always have one active environment' ,
277
+ auditUser,
278
+ } ) ,
273
279
) ;
274
280
}
275
281
}
0 commit comments