diff --git a/src/lib/features/segment/segment-controller.ts b/src/lib/features/segment/segment-controller.ts index 8ecf1b5e8045..7c96513395dc 100644 --- a/src/lib/features/segment/segment-controller.ts +++ b/src/lib/features/segment/segment-controller.ts @@ -354,39 +354,30 @@ export class SegmentsController extends Controller { user.id, ); - if (this.flagResolver.isEnabled('detectSegmentUsageInChangeRequests')) { - const mapStrategies = (strategy) => ({ - id: strategy.id, - projectId: strategy.projectId, - featureName: strategy.featureName, - strategyName: strategy.strategyName, - environment: strategy.environment, - }); + const segmentStrategies = strategies.strategies.map((strategy) => ({ + id: strategy.id, + projectId: strategy.projectId, + featureName: strategy.featureName, + strategyName: strategy.strategyName, + environment: strategy.environment, + })); - const mapChangeRequestStrategies = (strategy) => ({ - ...(strategy.id ? { id: strategy.id } : {}), - projectId: strategy.projectId, - featureName: strategy.featureName, - strategyName: strategy.strategyName, - environment: strategy.environment, - changeRequest: strategy.changeRequest, - }); + if (this.flagResolver.isEnabled('detectSegmentUsageInChangeRequests')) { + const changeRequestStrategies = + strategies.changeRequestStrategies.map((strategy) => ({ + ...('id' in strategy ? { id: strategy.id } : {}), + projectId: strategy.projectId, + featureName: strategy.featureName, + strategyName: strategy.strategyName, + environment: strategy.environment, + changeRequest: strategy.changeRequest, + })); res.json({ - strategies: strategies.strategies.map(mapStrategies), - changeRequestStrategies: strategies.changeRequestStrategies.map( - mapChangeRequestStrategies, - ), + strategies: segmentStrategies, + changeRequestStrategies, }); } else { - const segmentStrategies = strategies.strategies.map((strategy) => ({ - id: strategy.id, - projectId: strategy.projectId, - featureName: strategy.featureName, - strategyName: strategy.strategyName, - environment: strategy.environment, - })); - res.json({ strategies: segmentStrategies }); } } diff --git a/src/lib/services/segment-service.ts b/src/lib/services/segment-service.ts index 7aea2759670d..587b3d35c996 100644 --- a/src/lib/services/segment-service.ts +++ b/src/lib/services/segment-service.ts @@ -119,12 +119,16 @@ export class SegmentService implements ISegmentService { const strategies = await this.featureStrategiesStore.getStrategiesBySegment(id); - const changeRequestStrategies = - await this.changeRequestSegmentUsageReadModel.getStrategiesUsedInActiveChangeRequests( - id, - ); + if (this.flagResolver.isEnabled('detectSegmentUsageInChangeRequests')) { + const changeRequestStrategies = + await this.changeRequestSegmentUsageReadModel.getStrategiesUsedInActiveChangeRequests( + id, + ); + + return { strategies, changeRequestStrategies }; + } - return { strategies, changeRequestStrategies }; + return { strategies, changeRequestStrategies: [] }; } async isInUse(id: number): Promise {