From f7d85108e12fbe065f41df4c51d1eddb779503ad Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Thu, 8 Jan 2026 15:27:48 +0100 Subject: [PATCH] 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. --- backend/src/health.controller.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 backend/src/health.controller.ts diff --git a/backend/src/health.controller.ts b/backend/src/health.controller.ts new file mode 100644 index 0000000..adadf64 --- /dev/null +++ b/backend/src/health.controller.ts @@ -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(), + }; + } + } +}