From 997bd8e7e110ed4d16f57f5970227e10ffe55c37 Mon Sep 17 00:00:00 2001 From: nikhila-aot Date: Wed, 13 Mar 2024 22:39:32 -0700 Subject: [PATCH] added healthcheck api --- .../src/app/controllers/form.controller.ts | 8 ++++---- .../applications/src/app/services/form.service.ts | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/applications/src/app/controllers/form.controller.ts b/backend/applications/src/app/controllers/form.controller.ts index 2a43738f..8d6b3fd1 100644 --- a/backend/applications/src/app/controllers/form.controller.ts +++ b/backend/applications/src/app/controllers/form.controller.ts @@ -15,13 +15,13 @@ export class FormController { * @returns form count */ @Get('health') - async getFormCount(): Promise { - const formCount = await this.formService.formCount(); + async healthCheck(): Promise { + const formCount = await this.formService.healthCheck(); - if (formCount == 0) { + if (!formCount) { return Promise.reject({ statusCode: 404, - message: 'Form data not found', + message: 'Table not found', }); } return formCount; diff --git a/backend/applications/src/app/services/form.service.ts b/backend/applications/src/app/services/form.service.ts index 08c5ce73..4bc52c71 100644 --- a/backend/applications/src/app/services/form.service.ts +++ b/backend/applications/src/app/services/form.service.ts @@ -10,11 +10,20 @@ export class FormService { ) { } /** - * Gets count of submitted forms + * Checks if table exists * @returns form count */ - async formCount(): Promise { - return this.formRepository.count(); + async healthCheck(): Promise { + const tableExists = ( + await this.formRepository.manager.query( + `SELECT exists ( + SELECT FROM information_schema.tables + WHERE table_schema = 'epd_applications' + AND table_name = 'form' + )`, + ) + )[0].exists; + return tableExists; } /**