1import { Inject, Controller, Get } from "@nestjs/common";
2import { HealthService } from "./health.service.js";
3import { ApiError } from "../../common/errors.js";
4
5@Controller("health")
6export class HealthController {
7 constructor(@Inject(HealthService) private readonly health: HealthService) {}
8
9 @Get()
10 liveness() {
11 return this.health.liveness();
12 }
13
14
20 @Get("ready")
21 async ready() {
22 const result = await this.health.deep();
23 if (!result.ok) {
24 const down = (["postgres", "redis"] as const).filter((k) => !result.checks[k]);
25 throw new ApiError("SERVICE_UNAVAILABLE", 503, "Dependency unavailable.", [
26 { service: down.join(",") }
27 ]);
28 }
29 return { status: "ready" as const, checks: result.checks };
30 }
31
32
33 @Get("deep")
34 async deep() {
35 return this.ready();
36 }
37}
38