feat: add HealthController with database connection check

Introduced a HealthController to verify application status. Includes an endpoint to check database connectivity and returns health status with a timestamp.
This commit is contained in:
Mathis HERRIOT
2026-01-08 15:27:48 +01:00
parent d5775a821e
commit f7d85108e1

View File

@@ -0,0 +1,28 @@
import { Controller, Get } from "@nestjs/common";
import { sql } from "drizzle-orm";
import { DatabaseService } from "./database/database.service";
@Controller("health")
export class HealthController {
constructor(private readonly databaseService: DatabaseService) {}
@Get()
async check() {
try {
// Check database connection
await this.databaseService.db.execute(sql`SELECT 1`);
return {
status: "ok",
database: "connected",
timestamp: new Date().toISOString(),
};
} catch (error) {
return {
status: "error",
database: "disconnected",
message: error.message,
timestamp: new Date().toISOString(),
};
}
}
}