File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
questionnaire/questionnaire/utils/taskRunner/tasks/transformAndUpload Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff 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) {
128146function 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 {
You can’t perform that action at this time.
0 commit comments