1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-17 01:17:29 +02:00
unleash.unleash/src/lib/routes/admin-api/project/health-report.ts
Jaanus Sellin 73515d78ce
chore: remove simplifyProjectOverview flag (#9068)
Remove the flag and delete unused components.
2025-01-08 14:10:40 +02:00

74 lines
2.8 KiB
TypeScript

import type { Request, Response } from 'express';
import Controller from '../../controller';
import type { IUnleashServices } from '../../../types/services';
import type { IUnleashConfig } from '../../../types/option';
import type ProjectHealthService from '../../../services/project-health-service';
import type { Logger } from '../../../logger';
import type { IProjectParam } from '../../../types/model';
import { NONE } from '../../../types/permissions';
import type { OpenApiService } from '../../../services/openapi-service';
import { createResponseSchema } from '../../../openapi/util/create-response-schema';
import { getStandardResponses } from '../../../openapi/util/standard-responses';
import { serializeDates } from '../../../types/serialize-dates';
import {
healthReportSchema,
type HealthReportSchema,
} from '../../../openapi/spec/health-report-schema';
export default class ProjectHealthReport extends Controller {
private projectHealthService: ProjectHealthService;
private openApiService: OpenApiService;
private logger: Logger;
constructor(
config: IUnleashConfig,
{
projectHealthService,
openApiService,
}: Pick<IUnleashServices, 'projectHealthService' | 'openApiService'>,
) {
super(config);
this.logger = config.getLogger('/admin-api/project/health-report');
this.projectHealthService = projectHealthService;
this.openApiService = openApiService;
this.route({
method: 'get',
path: '/:projectId/health-report',
handler: this.getProjectHealthReport,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Projects'],
deprecated: true,
operationId: 'getProjectHealthReport',
summary: 'Get a health report for a project.',
description:
'This endpoint returns a health report for the specified project. This data is used for [the technical debt insights](https://docs.getunleash.io/reference/technical-debt)',
responses: {
200: createResponseSchema('healthReportSchema'),
...getStandardResponses(401, 403, 404),
},
}),
],
});
}
async getProjectHealthReport(
req: Request<IProjectParam>,
res: Response<HealthReportSchema>,
): Promise<void> {
const { projectId } = req.params;
const overview =
await this.projectHealthService.getProjectHealthReport(projectId);
this.openApiService.respondWithValidation(
200,
res,
healthReportSchema.$id,
serializeDates(overview),
);
}
}