-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth.controller.ts
More file actions
42 lines (39 loc) · 1.23 KB
/
health.controller.ts
File metadata and controls
42 lines (39 loc) · 1.23 KB
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
import { Controller, Get, UseGuards } from '@nestjs/common';
import { HealthService } from './health.service';
import {
ApiTags,
ApiOperation,
ApiOkResponse,
ApiUnauthorizedResponse,
ApiBearerAuth,
} from '@nestjs/swagger';
import { Roles } from '../decorators/role.decorator';
import { RolesGuard } from '../guards/roles.guard';
import { Role } from '../utils/common/constant/enum.constant';
@ApiTags('Health')
@Controller()
export class HealthController {
constructor(private readonly healthService: HealthService) {}
@Get('/health')
@ApiOperation({ summary: 'Liveness check' })
@ApiOkResponse({ description: 'Service is alive' })
async health() {
return this.healthService.getLiveness();
}
/**
* Protected endpoint that checks queue (Redis + RabbitMQ) health.
* Only accessible to users with Role.ADMIN.
*/
@Get('/queue-health')
@UseGuards(RolesGuard)
@Roles(Role.ADMIN)
@ApiBearerAuth()
@ApiOperation({
summary: 'Queue and dependent services health check (admin)',
})
@ApiOkResponse({ description: 'Queue and dependent services OK' })
@ApiUnauthorizedResponse({ description: 'Unauthorized or insufficient role' })
async queueHealth() {
return this.healthService.getQueueHealth();
}
}