2021-07-07 10:46:50 +02:00
|
|
|
import { Request, Response } from 'express';
|
|
|
|
import Controller from '../../controller';
|
|
|
|
import { IUnleashServices } from '../../../types/services';
|
|
|
|
import { IUnleashConfig } from '../../../types/option';
|
|
|
|
import ProjectHealthService from '../../../services/project-health-service';
|
|
|
|
import { Logger } from '../../../logger';
|
|
|
|
import { IArchivedQuery, IProjectParam } from '../../../types/model';
|
2022-06-08 15:31:34 +02:00
|
|
|
import { NONE } from '../../../types/permissions';
|
|
|
|
import { OpenApiService } from '../../../services/openapi-service';
|
2022-07-01 08:06:33 +02:00
|
|
|
import { createResponseSchema } from '../../../openapi/util/create-response-schema';
|
2022-06-08 15:31:34 +02:00
|
|
|
import {
|
|
|
|
healthOverviewSchema,
|
|
|
|
HealthOverviewSchema,
|
|
|
|
} from '../../../openapi/spec/health-overview-schema';
|
|
|
|
import { serializeDates } from '../../../types/serialize-dates';
|
|
|
|
import {
|
|
|
|
healthReportSchema,
|
|
|
|
HealthReportSchema,
|
|
|
|
} from '../../../openapi/spec/health-report-schema';
|
2022-11-30 12:41:53 +01:00
|
|
|
import { IAuthRequest } from '../../unleash-types';
|
2021-07-07 10:46:50 +02:00
|
|
|
|
|
|
|
export default class ProjectHealthReport extends Controller {
|
|
|
|
private projectHealthService: ProjectHealthService;
|
|
|
|
|
2022-06-08 15:31:34 +02:00
|
|
|
private openApiService: OpenApiService;
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
private logger: Logger;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
config: IUnleashConfig,
|
|
|
|
{
|
|
|
|
projectHealthService,
|
2022-06-08 15:31:34 +02:00
|
|
|
openApiService,
|
|
|
|
}: Pick<IUnleashServices, 'projectHealthService' | 'openApiService'>,
|
2021-07-07 10:46:50 +02:00
|
|
|
) {
|
|
|
|
super(config);
|
|
|
|
this.logger = config.getLogger('/admin-api/project/health-report');
|
|
|
|
this.projectHealthService = projectHealthService;
|
2022-06-08 15:31:34 +02:00
|
|
|
this.openApiService = openApiService;
|
|
|
|
|
|
|
|
this.route({
|
|
|
|
method: 'get',
|
|
|
|
path: '/:projectId',
|
|
|
|
handler: this.getProjectHealthOverview,
|
|
|
|
permission: NONE,
|
|
|
|
middleware: [
|
|
|
|
openApiService.validPath({
|
2022-08-12 11:37:57 +02:00
|
|
|
tags: ['Projects'],
|
2022-06-08 15:31:34 +02:00
|
|
|
operationId: 'getProjectHealthOverview',
|
|
|
|
responses: {
|
|
|
|
200: createResponseSchema('healthOverviewSchema'),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
this.route({
|
|
|
|
method: 'get',
|
|
|
|
path: '/:projectId/health-report',
|
|
|
|
handler: this.getProjectHealthReport,
|
|
|
|
permission: NONE,
|
|
|
|
middleware: [
|
|
|
|
openApiService.validPath({
|
2022-08-12 11:37:57 +02:00
|
|
|
tags: ['Projects'],
|
2022-06-08 15:31:34 +02:00
|
|
|
operationId: 'getProjectHealthReport',
|
|
|
|
responses: {
|
|
|
|
200: createResponseSchema('healthReportSchema'),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
2021-07-07 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
2022-06-08 15:31:34 +02:00
|
|
|
async getProjectHealthOverview(
|
2022-11-30 12:41:53 +01:00
|
|
|
req: IAuthRequest<IProjectParam, unknown, unknown, IArchivedQuery>,
|
2022-06-08 15:31:34 +02:00
|
|
|
res: Response<HealthOverviewSchema>,
|
2021-07-07 10:46:50 +02:00
|
|
|
): Promise<void> {
|
|
|
|
const { projectId } = req.params;
|
|
|
|
const { archived } = req.query;
|
2022-11-30 12:41:53 +01:00
|
|
|
const { user } = req;
|
2021-09-13 10:23:57 +02:00
|
|
|
const overview = await this.projectHealthService.getProjectOverview(
|
|
|
|
projectId,
|
|
|
|
archived,
|
2022-11-30 12:41:53 +01:00
|
|
|
user.id,
|
2021-09-13 10:23:57 +02:00
|
|
|
);
|
2022-06-08 15:31:34 +02:00
|
|
|
this.openApiService.respondWithValidation(
|
|
|
|
200,
|
|
|
|
res,
|
|
|
|
healthOverviewSchema.$id,
|
|
|
|
serializeDates(overview),
|
|
|
|
);
|
2021-07-07 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async getProjectHealthReport(
|
2022-06-08 15:31:34 +02:00
|
|
|
req: Request<IProjectParam>,
|
|
|
|
res: Response<HealthReportSchema>,
|
2021-07-07 10:46:50 +02:00
|
|
|
): Promise<void> {
|
|
|
|
const { projectId } = req.params;
|
2021-09-13 10:23:57 +02:00
|
|
|
const overview = await this.projectHealthService.getProjectHealthReport(
|
|
|
|
projectId,
|
|
|
|
);
|
2022-06-08 15:31:34 +02:00
|
|
|
this.openApiService.respondWithValidation(
|
|
|
|
200,
|
|
|
|
res,
|
|
|
|
healthReportSchema.$id,
|
|
|
|
serializeDates(overview),
|
|
|
|
);
|
2021-07-07 10:46:50 +02:00
|
|
|
}
|
|
|
|
}
|