diff --git a/src/app.controller.ts b/src/app.controller.ts index e5c7297..8076c0c 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -6,10 +6,16 @@ import { ApiResponse, ApiTags, } from '@nestjs/swagger'; +import { InjectConnection } from '@nestjs/mongoose'; +import { Connection } from 'mongoose'; + @ApiTags('health') @Controller() export class AppController { - constructor(private readonly appService: AppService) {} + constructor( + private readonly appService: AppService, + @InjectConnection() private readonly mongoConnection: Connection, + ) {} @ApiExcludeEndpoint(true) @Get() @@ -47,4 +53,35 @@ export class AppController { message: 'content ServiceApp is working', }; } + + @ApiOperation({ + summary: 'Deep health check', + description: 'Returns service health including dependency status', + }) + @ApiResponse({ + status: 200, + description: 'Health status with dependency checks', + schema: { + type: 'object', + properties: { + status: { type: 'string', example: 'ok' }, + services: { + type: 'object', + properties: { mongodb: { type: 'boolean' } }, + }, + uptime: { type: 'number' }, + timestamp: { type: 'string' }, + }, + }, + }) + @Get('/health') + deepHealth() { + const mongoOk = this.mongoConnection.readyState === 1; + return { + status: mongoOk ? 'ok' : 'degraded', + services: { mongodb: mongoOk }, + uptime: process.uptime(), + timestamp: new Date().toISOString(), + }; + } }