Skip to content

Commit

Permalink
added healthcheck api
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhila-aot committed Mar 14, 2024
1 parent 3093591 commit 997bd8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions backend/applications/src/app/controllers/form.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export class FormController {
* @returns form count
*/
@Get('health')
async getFormCount(): Promise<number> {
const formCount = await this.formService.formCount();
async healthCheck(): Promise<number> {
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;
Expand Down
15 changes: 12 additions & 3 deletions backend/applications/src/app/services/form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ export class FormService {
) { }

/**
* Gets count of submitted forms
* Checks if table exists
* @returns form count
*/
async formCount(): Promise<number> {
return this.formRepository.count();
async healthCheck(): Promise<any> {
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;
}

/**
Expand Down

0 comments on commit 997bd8e

Please sign in to comment.