-
-
Notifications
You must be signed in to change notification settings - Fork 658
/
project-insights-controller.ts
70 lines (63 loc) · 2.42 KB
/
project-insights-controller.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { Response } from 'express';
import Controller from '../../routes/controller';
import {
type IFlagResolver,
type IProjectParam,
type IUnleashConfig,
type IUnleashServices,
NONE,
serializeDates,
} from '../../types';
import type { ProjectInsightsService } from './project-insights-service';
import {
createResponseSchema,
projectInsightsSchema,
type ProjectInsightsSchema,
} from '../../openapi';
import { getStandardResponses } from '../../openapi/util/standard-responses';
import type { OpenApiService } from '../../services';
import type { IAuthRequest } from '../../routes/unleash-types';
export default class ProjectInsightsController extends Controller {
private projectInsightsService: ProjectInsightsService;
private openApiService: OpenApiService;
private flagResolver: IFlagResolver;
constructor(config: IUnleashConfig, services: IUnleashServices) {
super(config);
this.projectInsightsService = services.projectInsightsService;
this.openApiService = services.openApiService;
this.flagResolver = config.flagResolver;
this.route({
method: 'get',
path: '/:projectId/insights',
handler: this.getProjectInsights,
permission: NONE,
middleware: [
this.openApiService.validPath({
tags: ['Unstable'],
operationId: 'getProjectInsights',
summary: 'Get an overview of a project insights.',
description:
'This endpoint returns insights into the specified projects stats, health, lead time for changes, feature types used, members and change requests.',
responses: {
200: createResponseSchema('projectInsightsSchema'),
...getStandardResponses(401, 403, 404),
},
}),
],
});
}
async getProjectInsights(
req: IAuthRequest<IProjectParam, unknown, unknown, unknown>,
res: Response<ProjectInsightsSchema>,
): Promise<void> {
const { projectId } = req.params;
const insights =
await this.projectInsightsService.getProjectInsights(projectId);
this.openApiService.respondWithValidation(
200,
res,
projectInsightsSchema.$id,
serializeDates(insights),
);
}
}