diff --git a/src/lib/domain/project-health/project-health.ts b/src/lib/domain/project-health/project-health.ts index 248719e9e3c2..07a7b6be5bbe 100644 --- a/src/lib/domain/project-health/project-health.ts +++ b/src/lib/domain/project-health/project-health.ts @@ -1,6 +1,13 @@ import { hoursToMilliseconds } from 'date-fns'; -import type { IProjectHealthReport } from '../../types'; -import type { IFeatureType } from '../../types/stores/feature-type-store'; +import type { + IFeatureToggleStore, + IProject, + IProjectHealthReport, +} from '../../types'; +import type { + IFeatureType, + IFeatureTypeStore, +} from '../../types/stores/feature-type-store'; type IPartialFeatures = Array<{ stale?: boolean; @@ -58,3 +65,19 @@ export const calculateHealthRating = ( return rating; }; + +export const calculateProjectHealthRating = + ( + featureTypeStore: IFeatureTypeStore, + featureToggleStore: IFeatureToggleStore, + ) => + async ({ id }: Pick): Promise => { + const featureTypes = await featureTypeStore.getAll(); + + const toggles = await featureToggleStore.getAll({ + project: id, + archived: false, + }); + + return calculateHealthRating(toggles, featureTypes); + }; diff --git a/src/lib/features/project-status/project-status-service.ts b/src/lib/features/project-status/project-status-service.ts index 856673ae7a83..8345abe69de0 100644 --- a/src/lib/features/project-status/project-status-service.ts +++ b/src/lib/features/project-status/project-status-service.ts @@ -1,4 +1,4 @@ -import { calculateHealthRating } from '../../domain/project-health/project-health'; +import { calculateProjectHealthRating } from '../../domain/project-health/project-health'; import type { ProjectStatusSchema } from '../../openapi'; import type { IApiTokenStore, @@ -52,17 +52,6 @@ export class ProjectStatusService { this.featureToggleStore = featureToggleStore; } - private async calculateHealthRating(projectId: string): Promise { - const featureTypes = await this.featureTypeStore.getAll(); - - const toggles = await this.featureToggleStore.getAll({ - project: projectId, - archived: false, - }); - - return calculateHealthRating(toggles, featureTypes); - } - async getProjectStatus(projectId: string): Promise { const [ members, @@ -77,7 +66,10 @@ export class ProjectStatusService { this.apiTokenStore.countProjectTokens(projectId), this.segmentStore.getProjectSegmentCount(projectId), this.eventStore.getProjectRecentEventActivity(projectId), - this.calculateHealthRating(projectId), + calculateProjectHealthRating( + this.featureTypeStore, + this.featureToggleStore, + )({ id: projectId }), this.projectLifecycleSummaryReadModel.getProjectLifecycleSummary( projectId, ), diff --git a/src/lib/routes/admin-api/project/health-report.ts b/src/lib/routes/admin-api/project/health-report.ts index cf5d405602e9..77740cbae3a1 100644 --- a/src/lib/routes/admin-api/project/health-report.ts +++ b/src/lib/routes/admin-api/project/health-report.ts @@ -42,6 +42,9 @@ export default class ProjectHealthReport extends Controller { middleware: [ openApiService.validPath({ tags: ['Projects'], + deprecated: config.flagResolver.isEnabled( + 'simplifyProjectOverview', + ), operationId: 'getProjectHealthReport', summary: 'Get a health report for a project.', description: diff --git a/src/lib/services/project-health-service.ts b/src/lib/services/project-health-service.ts index 1b45fbeaaaa9..729da8d1e210 100644 --- a/src/lib/services/project-health-service.ts +++ b/src/lib/services/project-health-service.ts @@ -7,8 +7,8 @@ import type { IFeatureTypeStore } from '../types/stores/feature-type-store'; import type { IProjectStore } from '../features/project/project-store-type'; import type ProjectService from '../features/project/project-service'; import { - calculateHealthRating, calculateProjectHealth, + calculateProjectHealthRating, } from '../domain/project-health/project-health'; export default class ProjectHealthService { @@ -22,6 +22,8 @@ export default class ProjectHealthService { private projectService: ProjectService; + calculateHealthRating: (project: IProject) => Promise; + constructor( { projectStore, @@ -40,6 +42,10 @@ export default class ProjectHealthService { this.featureToggleStore = featureToggleStore; this.projectService = projectService; + this.calculateHealthRating = calculateProjectHealthRating( + this.featureTypeStore, + this.featureToggleStore, + ); } async getProjectHealthReport( @@ -64,17 +70,6 @@ export default class ProjectHealthService { }; } - async calculateHealthRating(project: IProject): Promise { - const featureTypes = await this.featureTypeStore.getAll(); - - const toggles = await this.featureToggleStore.getAll({ - project: project.id, - archived: false, - }); - - return calculateHealthRating(toggles, featureTypes); - } - async setHealthRating(): Promise { const projects = await this.projectStore.getAll();