import { Controller, Get, HttpException, HttpStatus } from "@nestjs/common"; import { getPrismaClient } from "@b2bcall/database"; import { getRedisClient } from "../common/redis"; @Controller("health") export class HealthController { @Get() root() { return { status: "ok" }; } @Get("live") live() { return { status: "ok" }; } @Get("ready") async ready() { const checks: Record = { postgres: "ok", redis: "ok" }; try { await getPrismaClient().$queryRaw`SELECT 1`; } catch { checks.postgres = "fail"; } try { await getRedisClient().ping(); } catch { checks.redis = "fail"; } const healthy = Object.values(checks).every((v) => v === "ok"); if (!healthy) { throw new HttpException({ status: "unhealthy", checks }, HttpStatus.SERVICE_UNAVAILABLE); } return { status: "ok", checks }; } }