Skip to content

Commit 2db54cc

Browse files
committed
Add function to remove unanswered questions before uploading to S3
1 parent 087145e commit 2db54cc

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

questionnaire/questionnaire/utils/taskRunner/tasks/transformAndUpload/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ function getDeclaration(questionnaire) {
120120
return undefined;
121121
}
122122

123+
/**
124+
* Removes all unanswered questions from the schema
125+
* @param answers - The themed content composed of questionnaire answers
126+
* @returns A themed object without any unanswered questions
127+
*/
128+
function trimUnansweredQuestions(answers) {
129+
const trimmedAnswers = [];
130+
answers.forEach(theme => {
131+
theme.values = theme.values.filter(
132+
question => !(question.value === undefined && question.values === undefined)
133+
);
134+
if (theme.values.length !== 0) {
135+
trimmedAnswers.push(theme);
136+
}
137+
});
138+
return trimmedAnswers;
139+
}
140+
123141
/**
124142
* Transforms the questionnaire object into the necessary downstream format.
125143
* @param {questionnaire} questionnaire - The raw questionnaire object
@@ -128,8 +146,9 @@ function getDeclaration(questionnaire) {
128146
function transformQuestionnaire(questionnaire) {
129147
const section = questionnaire.getSection('p--check-your-answers');
130148
const sectionSchema = section.getSchema();
131-
const themeContent =
132-
sectionSchema.properties['p-check-your-answers'].properties.summaryInfo.summaryStructure;
149+
const themeContent = trimUnansweredQuestions(
150+
sectionSchema.properties['p-check-your-answers'].properties.summaryInfo.summaryStructure
151+
);
133152
flattenAnswers(themeContent);
134153

135154
return {

0 commit comments

Comments
 (0)