Skip to content

Commit

Permalink
Update task assignee question validation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexd-bes committed Aug 28, 2024
1 parent 96c75be commit a2b0e99
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TaskConfigValidator extends JsonFieldValidator {
getFieldValidators(rowIndex) {
const referencesExistingSurvey = this.constructReferencesExistingSurvey();

const pointsToAnotherQuestion = this.constructPointsToAnotherQuestion(rowIndex);
const pointsToAnotherQuestion = this.constructReferencesPreceedingQuestion(rowIndex, ['User']);

return {
shouldCreateTask: [this.constructReferencesPreceedingMandatoryQuestion(rowIndex, ['Binary'])],
Expand Down Expand Up @@ -47,6 +47,22 @@ export class TaskConfigValidator extends JsonFieldValidator {
};
};

constructReferencesPreceedingQuestion = (rowIndex, acceptedQuestionTypes) => {
return value => {
const question = this.findOtherQuestion(value, rowIndex, rowIndex);
if (!question) {
throw new ValidationError('Referenced question does not exist');
}

if (!acceptedQuestionTypes.includes(question.type)) {
throw new ValidationError(
`Referenced question should be of type ${acceptedQuestionTypes.join(' or ')}`,
);
}
return true;
};
};

constructReferencesPreceedingMandatoryQuestion = (rowIndex, acceptedQuestionTypes) => {
return value => {
const question = this.findOtherQuestion(value, rowIndex, rowIndex);
Expand Down

0 comments on commit a2b0e99

Please sign in to comment.