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

100% Statements 15/15
100% Branches 0/0
100% Functions 2/2
100% Lines 15/15

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  59x     59x 59x 59x   59x   59x       141x 141x 141x 141x 141x 141x 141x       1x     1x      
import { Request, Response } from 'express';
import Controller from '../../controller';
import { IUnleashConfig } from '../../../types/option';
import { IUnleashServices } from '../../../types/services';
import ProjectFeaturesController from './features';
import EnvironmentsController from './environments';
import ProjectHealthReport from './health-report';
import ProjectService from '../../../services/project-service';
import VariantsController from './variants';
 
export default class ProjectApi extends Controller {
    private projectService: ProjectService;
 
    constructor(config: IUnleashConfig, services: IUnleashServices) {
        super(config);
        this.projectService = services.projectService;
        this.get('/', this.getProjects);
        this.use('/', new ProjectFeaturesController(config, services).router);
        this.use('/', new EnvironmentsController(config, services).router);
        this.use('/', new ProjectHealthReport(config, services).router);
        this.use('/', new VariantsController(config, services).router);
    }
 
    async getProjects(req: Request, res: Response): Promise<void> {
        const projects = await this.projectService.getProjects({
            id: 'default',
        });
        res.json({ version: 1, projects }).end();
    }
}