import { Controller, Get } from '@nestjs/common'; import { HealthCheckService, HealthCheck, HealthCheckResult, } from '@nestjs/terminus'; import { Messager } from '../secondaries/messager'; import { PrismaHealthIndicatorUseCase } from '../../domain/usecases/prisma.health-indicator.usecase'; @Controller('health') export class HealthController { constructor( private readonly _prismaHealthIndicatorUseCase: PrismaHealthIndicatorUseCase, private _healthCheckService: HealthCheckService, private _messager: Messager, ) {} @Get() @HealthCheck() async check() { try { return await this._healthCheckService.check([ async () => this._prismaHealthIndicatorUseCase.isHealthy('prisma'), ]); } catch (error) { const healthCheckResult: HealthCheckResult = error.response; this._messager.publish( 'logging.matcher.health.crit', JSON.stringify(healthCheckResult.error), ); throw error; } } }