23 lines
841 B
TypeScript
23 lines
841 B
TypeScript
import { Controller, Get, HttpException, HttpStatus, Inject } from '@nestjs/common';
|
|
import { ApiOkResponse, ApiServiceUnavailableResponse, ApiTags } from '@nestjs/swagger';
|
|
|
|
import { HealthResponseDto } from '../../../libs/http-contracts/src/health.dto';
|
|
import { HealthService } from './health.service';
|
|
|
|
@ApiTags('health')
|
|
@Controller('health')
|
|
export class HealthController {
|
|
constructor(@Inject(HealthService) private readonly healthService: HealthService) {}
|
|
|
|
@Get()
|
|
@ApiOkResponse({ type: HealthResponseDto })
|
|
@ApiServiceUnavailableResponse({ type: HealthResponseDto })
|
|
async getHealth(): Promise<HealthResponseDto> {
|
|
const response = await this.healthService.check();
|
|
if (response.status === 'unavailable') {
|
|
throw new HttpException(response, HttpStatus.SERVICE_UNAVAILABLE);
|
|
}
|
|
return response;
|
|
}
|
|
}
|