Skip to content

Commit

Permalink
chore: move enterprise check further left
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Nov 27, 2023
1 parent 249aac6 commit 6249908
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
47 changes: 19 additions & 28 deletions src/lib/features/segment/segment-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/lib/services/segment-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand Down

0 comments on commit 6249908

Please sign in to comment.