Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/srs 310 #648

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading