-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3127 from ONSdigital/EAR-2394-Validation-for-surv…
…eyID-when-SDS-is-linked Created the validation message and imported to setting page
- Loading branch information
Showing
5 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
eq-author-api/src/validation/customKeywords/validateSurveyId.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const createValidationError = require("../createValidationError"); | ||
const { | ||
ERR_SURVEY_ID_MISMATCH, | ||
} = require("../../../constants/validationErrorCodes"); | ||
|
||
module.exports = (ajv) => | ||
ajv.addKeyword({ | ||
keyword: "validateSurveyId", | ||
validate: function isValid( | ||
_schema, | ||
questionnaireSurveyId, // gives the data entered into the survey ID field | ||
_parentSchema, | ||
{ | ||
instancePath, // gives the path /surveyId | ||
rootData: questionnaire, // gives the whole questionnaire object | ||
parentDataProperty: fieldName, // gives the field name surveyId | ||
} | ||
) { | ||
// Get the supplementary data from the questionnaire object | ||
const supplementaryData = questionnaire.supplementaryData; | ||
|
||
// If supplementaryData exists and contains a surveyId, and supplementaryData's surveyId doesn't match the questionnaire's surveyId, throw a validation error | ||
if ( | ||
supplementaryData && | ||
supplementaryData.surveyId && | ||
questionnaireSurveyId !== supplementaryData.surveyId | ||
) { | ||
isValid.errors = [ | ||
createValidationError( | ||
instancePath, | ||
fieldName, | ||
ERR_SURVEY_ID_MISMATCH, | ||
questionnaire, | ||
ERR_SURVEY_ID_MISMATCH | ||
), | ||
]; | ||
return false; | ||
} | ||
|
||
return true; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters