-
Notifications
You must be signed in to change notification settings - Fork 0
Dev release #2
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
Dev release #2
Changes from all commits
c891109
ac41726
7386deb
e5402e5
59e0090
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Deploy Survey Dev | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - dev-release | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Deploy to server | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: SSH and deploy | ||
| uses: appleboy/[email protected] | ||
| with: | ||
| host: ${{ secrets.DEV_SSH_HOST }} | ||
| username: ${{ secrets.DEV_SSH_USER }} | ||
| key: ${{ secrets.DEV_SSH_PRIVATE_KEY }} | ||
| script: | | ||
| cd ~/Microservices/survey-dev-configs | ||
| ./deploy.sh dev-release |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -134,7 +134,7 @@ export class ResponseService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return APIResponse.success( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| apiId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { data: saved }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| saved, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HttpStatus.CREATED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RESPONSE_MESSAGES.RESPONSE_CREATE_SUCCESS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -186,7 +186,7 @@ export class ResponseService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return APIResponse.success( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| apiId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { data: result }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HttpStatus.OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RESPONSE_MESSAGES.RESPONSE_LIST_SUCCESS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -225,7 +225,7 @@ export class ResponseService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return APIResponse.success( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| apiId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { data: surveyResponse }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| surveyResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HttpStatus.OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RESPONSE_MESSAGES.RESPONSE_READ_SUCCESS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -322,7 +322,7 @@ export class ResponseService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return APIResponse.success( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| apiId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { data: saved }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| saved, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HttpStatus.OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RESPONSE_MESSAGES.RESPONSE_UPDATE_SUCCESS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -434,7 +434,7 @@ export class ResponseService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return APIResponse.success( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| apiId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { data: saved }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| saved, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HttpStatus.OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RESPONSE_MESSAGES.RESPONSE_SUBMIT_SUCCESS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -494,7 +494,7 @@ export class ResponseService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return APIResponse.success( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| apiId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { data: result }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HttpStatus.OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RESPONSE_MESSAGES.RESPONSE_STATS_SUCCESS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -532,14 +532,32 @@ export class ResponseService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return surveyResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private isConditionMet(field: any, allFields: any[], responseData: Record<string, any>): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const logic = field.conditionalLogic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!logic || !logic.depends_on || !logic.show_if) return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const parentField = allFields.find(f => f.fieldName === logic.depends_on); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!parentField) return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const parentValue = responseData[parentField.fieldId]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const showIf: string[] = logic.show_if; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Array.isArray(parentValue)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return parentValue.some(v => showIf.includes(v)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return showIf.includes(parentValue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+535
to
+549
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation of
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private validateRequiredFields(survey: any, surveyResponse: SurveyResponse): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const errors: string[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const allFields = (survey.sections || []).flatMap((s: any) => s.fields || []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const section of survey.sections || []) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const field of section.fields || []) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (field.isRequired) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const value = surveyResponse.responseData[field.fieldId]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const fileIds = surveyResponse.fileUploadIds[field.fieldId]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (field.isRequired && this.isConditionMet(field, allFields, surveyResponse.responseData ?? {})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const value = (surveyResponse.responseData ?? {})[field.fieldId]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const fileIds = (surveyResponse.fileUploadIds ?? {})[field.fieldId]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+554
to
+560
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To optimize the validation process and improve code readability, create a Map for field lookups once and extract const allFields = (survey.sections || []).flatMap((s: any) => s.fields || []);
const fieldsMap = new Map(allFields.map(f => [f.fieldName, f]));
const responseData = surveyResponse.responseData ?? {};
const fileUploadIds = surveyResponse.fileUploadIds ?? {};
for (const section of survey.sections || []) {
for (const field of section.fields || []) {
if (field.isRequired && this.isConditionMet(field, fieldsMap, responseData)) {
const value = responseData[field.fieldId];
const fileIds = fileUploadIds[field.fieldId]; |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isUploadField = ['image_upload', 'video_upload', 'file_upload'].includes( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| field.fieldType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
surveyIdfield should be mandatory when creating a response. Marking it as@IsOptional()allows requests with a missingsurveyIdto pass validation, which will subsequently cause aNotFoundExceptionin the service layer when it fails to fetch the survey. It is better to enforce this requirement at the DTO level to provide a clearer error response (400 Bad Request).