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';
|
2021-08-13 10:36:19 +02:00
|
|
|
import { handleErrors } from '../../util';
|
2021-07-07 10:46:50 +02:00
|
|
|
|
|
|
|
export default class ProjectHealthReport extends Controller {
|
|
|
|
private projectHealthService: ProjectHealthService;
|
|
|
|
|
|
|
|
private logger: Logger;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
config: IUnleashConfig,
|
|
|
|
{
|
|
|
|
projectHealthService,
|
|
|
|
}: Pick<IUnleashServices, 'projectHealthService'>,
|
|
|
|
) {
|
|
|
|
super(config);
|
|
|
|
this.logger = config.getLogger('/admin-api/project/health-report');
|
|
|
|
this.projectHealthService = projectHealthService;
|
|
|
|
this.get('/:projectId', this.getProjectOverview);
|
|
|
|
this.get('/:projectId/health-report', this.getProjectHealthReport);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getProjectOverview(
|
|
|
|
req: Request<IProjectParam, any, any, IArchivedQuery>,
|
|
|
|
res: Response,
|
|
|
|
): Promise<void> {
|
|
|
|
const { projectId } = req.params;
|
|
|
|
const { archived } = req.query;
|
|
|
|
try {
|
|
|
|
const overview = await this.projectHealthService.getProjectOverview(
|
|
|
|
projectId,
|
|
|
|
archived,
|
|
|
|
);
|
|
|
|
res.json(overview);
|
|
|
|
} catch (e) {
|
|
|
|
handleErrors(res, this.logger, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async getProjectHealthReport(
|
|
|
|
req: Request<IProjectParam, any, any, any>,
|
|
|
|
res: Response,
|
|
|
|
): Promise<void> {
|
|
|
|
const { projectId } = req.params;
|
|
|
|
try {
|
2021-08-12 15:04:37 +02:00
|
|
|
const overview =
|
|
|
|
await this.projectHealthService.getProjectHealthReport(
|
|
|
|
projectId,
|
|
|
|
);
|
2021-07-07 10:46:50 +02:00
|
|
|
res.json({
|
|
|
|
version: 2,
|
|
|
|
...overview,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
handleErrors(res, this.logger, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|