Skip to content

Commit

Permalink
feat: add BE validation that first step of MRF workflow cannot be app…
Browse files Browse the repository at this point in the history
…roval
  • Loading branch information
kevin9foong committed Sep 11, 2024
1 parent 5275843 commit 4c26b03
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/app/modules/form/admin-form/admin-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ export const createForm = (
)
}

const isFirstStepApproval = workflow[0] && workflow[0].approval_field
if (isFirstStepApproval) {
return errAsync(
new MalformedParametersError(
'First step of workflow cannot be an approval step',
),
)
}

const yesNoFieldIds = formParams.form_fields
?.filter((field) => field.fieldType === BasicField.YesNo)
.map((field) => field._id.toString())
Expand Down Expand Up @@ -1349,6 +1358,16 @@ export const createWorkflowStep = (
}
}

const isFirstStep =
(originalForm as IPopulatedMultirespondentForm).workflow.length === 0
if (isFirstStep && newWorkflowStep.approval_field) {
return errAsync(
new MalformedParametersError(
'First step of workflow cannot be an approval step',
),
)
}

const selectedApprovalField = newWorkflowStep.approval_field
if (selectedApprovalField) {
const yesNoFieldIds = originalForm.form_fields
Expand Down Expand Up @@ -1461,6 +1480,15 @@ export const updateFormWorkflowStep = (
}
}

const isFirstStep = stepNumber === 0
if (isFirstStep && updatedWorkflowStep.approval_field) {
return errAsync(
new MalformedParametersError(
'First step of workflow cannot be an approval step',
),
)
}

const selectedApprovalField = updatedWorkflowStep.approval_field
if (selectedApprovalField) {
const yesNoFieldIds = originalForm.form_fields
Expand Down

0 comments on commit 4c26b03

Please sign in to comment.