-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
health-check.schema.ts
52 lines (49 loc) · 1.27 KB
/
health-check.schema.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
import { HealthCheckStatus } from './health-check-result.interface';
import { HealthIndicatorResult } from '../health-indicator';
import type {} from '@nestjs/swagger';
// These examples will be displayed on Swagger
const DB_EXAMPLE: HealthIndicatorResult = { database: { status: 'up' } };
const REDIS_EXAMPLE: HealthIndicatorResult = {
redis: { status: 'down', message: 'Could not connect' },
};
const COMBINED_EXAMPLE: HealthIndicatorResult = {
...DB_EXAMPLE,
...REDIS_EXAMPLE,
};
const healthIndicatorSchema = (example: HealthIndicatorResult) => ({
type: 'object',
example,
additionalProperties: {
type: 'object',
properties: {
status: {
type: 'string',
},
},
additionalProperties: {
type: 'string',
},
},
});
export function getHealthCheckSchema(status: HealthCheckStatus) {
return {
type: 'object',
properties: {
status: {
type: 'string',
example: status,
},
info: {
...healthIndicatorSchema(DB_EXAMPLE),
nullable: true,
},
error: {
...healthIndicatorSchema(status === 'error' ? REDIS_EXAMPLE : {}),
nullable: true,
},
details: healthIndicatorSchema(
status === 'error' ? COMBINED_EXAMPLE : DB_EXAMPLE,
),
},
};
}