Skip to content

Commit

Permalink
Merge pull request #648 from bcgov/feat/srs-310
Browse files Browse the repository at this point in the history
Feat/srs 310
  • Loading branch information
midhun-aot authored Mar 14, 2024
2 parents b6adbf4 + 25c8f29 commit cb87404
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
28 changes: 22 additions & 6 deletions backend/applications/src/app/controllers/form.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, Get, Param, Patch, Post, Put } from '@nestjs/common';
import { Resource, Unprotected } from 'nest-keycloak-connect';
import { Unprotected } from 'nest-keycloak-connect';
import { SubmissionResponse } from '../dto/submissionResponse.dto';
import { Form } from '../entities/form.entity';
import { FormService } from '../services/form.service';
Expand All @@ -8,7 +8,24 @@ import { FormService } from '../services/form.service';
//@Resource('application-service')
@Unprotected()
export class FormController {
constructor(private formService: FormService) {}
constructor(private formService: FormService) { }

/**
* Checks if table exists
* @returns boolean
*/
@Get('health')
async healthCheck(): Promise<number> {
const formCount = await this.formService.healthCheck();

if (!formCount) {
return Promise.reject({
statusCode: 404,
message: 'Table not found',
});
}
return formCount;
}

/**
* Get a submitted form using
Expand All @@ -25,12 +42,11 @@ export class FormController {
formId,
);

if(!savedSubmission)
{
if (!savedSubmission) {
return Promise.reject({
statusCode: 404,
message: 'Form data not found'
})
message: 'Form data not found',
});
}

const submissionResponse: SubmissionResponse =
Expand Down
25 changes: 19 additions & 6 deletions backend/applications/src/app/services/form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,24 @@ import { Form } from '../entities/form.entity';
export class FormService {
constructor(
@InjectRepository(Form) private readonly formRepository: Repository<Form>,
) {}
) { }

/**
* Checks if table exists
* @returns boolean
*/
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;
}

/**
* Creates new form submission
Expand Down Expand Up @@ -36,7 +53,7 @@ export class FormService {

buildUpdateString = (pathText, newValue) => {
const returnString =
'jsonb_set("form_data"::jsonb,' + pathText + ',' + newValue + ')';
'jsonb_set("form_data"::jsonb,' + pathText + ',' + newValue + ')';
return returnString;
};

Expand All @@ -46,7 +63,6 @@ export class FormService {
formId,
submissionId,
) => {

for (const property in partialUpdateObject) {
if (typeof partialUpdateObject[property] === 'object') {
this.processContent(
Expand All @@ -64,14 +80,11 @@ export class FormService {
} else {
objectName = property;
}


const pathText = "'{" + objectName + "}'";

const newValue = '\'"' + partialUpdateObject[property] + '"\'';



await this.formRepository
.createQueryBuilder()
.update(Form)
Expand Down

0 comments on commit cb87404

Please sign in to comment.