import { Controller, Get, ServiceUnavailableException } from '@nestjs/common'; import { SkipThrottle } from '@nestjs/throttler'; import { PrismaService } from './prisma/prisma.service'; /** Sondes de santé : watchdog (cron) et surveillance externe (UptimeRobot…). */ @Controller('health') @SkipThrottle() export class HealthController { constructor(private prisma: PrismaService) {} /** Le process répond (utilisé par watchdog.sh). */ @Get() check() { return { status: 'ok' }; } /** Le process ET la base répondent. */ @Get('ready') async ready() { try { await this.prisma.$queryRaw`SELECT 1`; return { status: 'ok', database: 'ok' }; } catch { throw new ServiceUnavailableException({ status: 'error', database: 'unreachable' }); } } }