All files / src/lib/routes/admin-api/project health-report.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 3/3
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54  59x             59x                     141x 141x 141x 141x 141x             7x 7x 7x       6x             5x 5x     4x            
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';
 
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;
        const overview = await this.projectHealthService.getProjectOverview(
            projectId,
            archived,
        );
        res.json(overview);
    }
 
    async getProjectHealthReport(
        req: Request<IProjectParam, any, any, any>,
        res: Response,
    ): Promise<void> {
        const { projectId } = req.params;
        const overview = await this.projectHealthService.getProjectHealthReport(
            projectId,
        );
        res.json({
            version: 2,
            ...overview,
        });
    }
}