import { Controller } from '@nestjs/common'; import { GrpcMethod } from '@nestjs/microservices'; import { PrismaHealthIndicatorUseCase } from '../../domain/usecases/prisma.health-indicator.usecase'; enum ServingStatus { UNKNOWN = 0, SERVING = 1, NOT_SERVING = 2, } interface HealthCheckRequest { service: string; } interface HealthCheckResponse { status: ServingStatus; } @Controller() export class HealthServerController { constructor( private readonly prismaHealthIndicatorUseCase: PrismaHealthIndicatorUseCase, ) {} @GrpcMethod('Health', 'Check') async check( // eslint-disable-next-line @typescript-eslint/no-unused-vars data: HealthCheckRequest, // eslint-disable-next-line @typescript-eslint/no-unused-vars metadata: any, ): Promise { const healthCheck = await this.prismaHealthIndicatorUseCase.isHealthy( 'prisma', ); return { status: healthCheck['prisma'].status == 'up' ? ServingStatus.SERVING : ServingStatus.NOT_SERVING, }; } }