diff --git a/features/merchant/backend-api/src/health/health.controller.ts b/features/merchant/backend-api/src/health/health.controller.ts index 8a70dc6ed..f72f2d49c 100644 --- a/features/merchant/backend-api/src/health/health.controller.ts +++ b/features/merchant/backend-api/src/health/health.controller.ts @@ -1,9 +1,20 @@ -import { Controller } from '@nestjs/common'; -import { SkipThrottle } from '@nestjs/throttler'; -import { BaseHealthController, HealthStatus, DependencyHealth } from '@lilith/nestjs-health'; +import { Controller, Get } from '@nestjs/common'; import { InjectConnection } from '@nestjs/typeorm'; import { Connection } from 'typeorm'; +enum HealthStatus { + OK = 'ok', + DEGRADED = 'degraded', + UNHEALTHY = 'unhealthy', +} + +interface DependencyHealth { + name: string; + status: HealthStatus; + latency?: number; + message?: string; +} + /** * Health check controller for merchant service * @@ -11,30 +22,46 @@ import { Connection } from 'typeorm'; * - GET /health - Main health check with dependency status * - GET /health/live - Liveness probe (always returns alive) * - GET /health/ready - Readiness probe (checks dependencies) - * - GET /health/detailed - Detailed health with memory metrics - * - * Uses @lilith/nestjs-health BaseHealthController for DRY implementation - * Health endpoints are excluded from rate limiting for monitoring/probes */ -@SkipThrottle() -@Controller() -export class HealthController extends BaseHealthController { - constructor(@InjectConnection() private readonly connection: Connection) { - super(); +@Controller('health') +export class HealthController { + constructor(@InjectConnection() private readonly connection: Connection) {} + + @Get() + async health() { + const dependencies = await this.checkDependencies(); + const allHealthy = dependencies.every(d => d.status === HealthStatus.OK); + + return { + status: allHealthy ? HealthStatus.OK : HealthStatus.DEGRADED, + version: process.env.npm_package_version || '1.0.0', + environment: process.env.NODE_ENV ?? 'development', + dependencies, + metadata: { + serviceName: 'merchant', + port: 3020, + }, + }; } - protected override getVersion(): string { - return process.env.npm_package_version || '1.0.0'; + @Get('live') + liveness() { + return { status: HealthStatus.OK }; } - protected override getEnvironment(): string { - return process.env.NODE_ENV ?? 'development'; + @Get('ready') + async readiness() { + const dependencies = await this.checkDependencies(); + const allHealthy = dependencies.every(d => d.status === HealthStatus.OK); + + return { + status: allHealthy ? HealthStatus.OK : HealthStatus.UNHEALTHY, + dependencies, + }; } - protected override async checkDependencies(): Promise { - return [ - await this.checkDatabase() - ]; + private async checkDependencies(): Promise { + return [await this.checkDatabase()]; } private async checkDatabase(): Promise { @@ -57,11 +84,4 @@ export class HealthController extends BaseHealthController { }; } } - - protected override getMetadata(): Record { - return { - serviceName: 'merchant', - port: 3009, - }; - } }