Skip to content

Commit

Permalink
fixed the conditional statement arrangements
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhanam76 committed Nov 21, 2024
1 parent 7b006d8 commit 9776c56
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions eq-author-api/src/validation/customKeywords/validateSurveyId.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,39 @@ module.exports = (ajv) =>
),
];
return false;
} else {
if (
typeof questionnaire.surveyId === "string" &&
questionnaire.surveyId.length > 0 &&
!questionnaire.surveyId.match(/^\d{3}$/)
) {
isValid.errors = [
createValidationError(
instancePath,
fieldName,
ERR_INVALID,
questionnaire,
ERR_INVALID
),
];
return false;
// If supplementaryData exists and contains a surveyId, and supplementaryData's surveyId doesn't match the questionnaire's surveyId, throw a validation error
} else if (
supplementaryData &&
supplementaryData.surveyId &&
questionnaireSurveyId !== supplementaryData.surveyId
) {
isValid.errors = [
createValidationError(
instancePath,
fieldName,
ERR_SURVEY_ID_MISMATCH,
questionnaire,
ERR_SURVEY_ID_MISMATCH
),
];

return false;
}
} else if (
typeof questionnaire.surveyId === "string" &&
questionnaire.surveyId.length > 0 &&
!questionnaire.surveyId.match(/^\d{3}$/)
) {
isValid.errors = [
createValidationError(
instancePath,
fieldName,
ERR_INVALID,
questionnaire,
ERR_INVALID
),
];
return false;
// If supplementaryData exists and contains a surveyId, and supplementaryData's surveyId doesn't match the questionnaire's surveyId, throw a validation error
} else if (
supplementaryData &&
supplementaryData.surveyId &&
questionnaireSurveyId !== supplementaryData.surveyId
) {
isValid.errors = [
createValidationError(
instancePath,
fieldName,
ERR_SURVEY_ID_MISMATCH,
questionnaire,
ERR_SURVEY_ID_MISMATCH
),
];

return false;
} else {
return true;
}
},
Expand Down

0 comments on commit 9776c56

Please sign in to comment.