diff --git a/src/eq_schema/builders/confirmationPage/ConfirmationPage.js b/src/eq_schema/builders/confirmationPage/ConfirmationPage.js index 1cef901c..7dcce0e6 100644 --- a/src/eq_schema/builders/confirmationPage/ConfirmationPage.js +++ b/src/eq_schema/builders/confirmationPage/ConfirmationPage.js @@ -100,7 +100,7 @@ const buildAuthorConfirmationQuestion = (page, groupId, routing, ctx) => { } if (page.confirmation.qCode) { - confirmationAnswerObject.qCode = page.confirmation.qCode.replace(/\s+$/, ''); + confirmationAnswerObject.qCode = page.confirmation.qCode.trim(); } const confirmationQuestionBlock = new Block( diff --git a/src/eq_schema/builders/routing2/newRoutingDestination/index.js b/src/eq_schema/builders/routing2/newRoutingDestination/index.js index 3dcb4605..98a43227 100644 --- a/src/eq_schema/builders/routing2/newRoutingDestination/index.js +++ b/src/eq_schema/builders/routing2/newRoutingDestination/index.js @@ -2,7 +2,7 @@ const routingConditionConversion = require("../../../../utils/routingConditionCo const { getMetadataKey, } = require("../../../../utils/contentUtils/getMetadataKey"); -const { getValueSource } = require("../../valueSource") +const { getValueSource } = require("../../valueSource"); const { getListFromAll } = require("../../../../utils/functions/listGetters"); const { flatMap, filter } = require("lodash"); @@ -23,7 +23,9 @@ const getOptionsFromQuestionaire = (questionnaire) => { const getOptionValues = (optionIds, questionnaire) => { const options = getOptionsFromQuestionaire(questionnaire); - const optionResults = optionIds.map((id) => filter(options, { id })[0].label.replace(/\s+$/, '')); + const optionResults = optionIds.map((id) => + filter(options, { id })[0].label.trim() + ); if (optionResults === undefined || optionResults.length < 0) { return null; @@ -56,9 +58,7 @@ const buildAnswerObject = ( { left, condition, secondaryCondition, right }, ctx ) => { - let returnVal = [ - getValueSource(ctx, left.answerId) - ]; + let returnVal = [getValueSource(ctx, left.answerId)]; if (right.type === "DateValue") { returnVal = [ @@ -204,7 +204,7 @@ const checkValidRoutingType = (expression, ctx) => { return buildAnswerObject(expression, ctx); } else if (expression.left.type === "Metadata") { return buildMetadataObject(expression, ctx); - } else if (expression.left.type === "List" ) { + } else if (expression.left.type === "List") { return buildListObject(expression, ctx); } else { throw new Error( diff --git a/src/eq_schema/schema/Answer/index.js b/src/eq_schema/schema/Answer/index.js index 6d1c4c2c..e6560dc1 100644 --- a/src/eq_schema/schema/Answer/index.js +++ b/src/eq_schema/schema/Answer/index.js @@ -48,7 +48,7 @@ class Answer { if (!ctx || (answer.qCode && ctx.questionnaireJson.dataVersion !== "3")) { if (answer.type !== CHECKBOX) { - this.q_code = answer.qCode.replace(/\s+$/, ""); + this.q_code = answer.qCode.trim(); } } @@ -272,16 +272,10 @@ class Answer { id: `answer${additionalAnswer.id}`, mandatory: properties.required, }; - option.detail_answer.label = option.detail_answer.label.replace( - /\s+$/, - "" - ); + option.detail_answer.label = option.detail_answer.label.trim(); if (ctx.questionnaireJson.dataVersion !== "3") { if (additionalAnswer.qCode && type !== "Checkbox") { - option.detail_answer.q_code = additionalAnswer.qCode.replace( - /\s+$/, - "" - ); + option.detail_answer.q_code = additionalAnswer.qCode.trim(); } } } diff --git a/src/eq_schema/schema/Question/index.js b/src/eq_schema/schema/Question/index.js index ad20d748..a1ace107 100644 --- a/src/eq_schema/schema/Question/index.js +++ b/src/eq_schema/schema/Question/index.js @@ -7,8 +7,11 @@ const { wrapContents, reversePipeContent, } = require("../../../utils/compoundFunctions"); -const { getList, getSupplementaryList } = require("../../../utils/functions/listGetters"); -const { getPagesByListId } = require("../../../utils/functions/pageGetters") +const { + getList, + getSupplementaryList, +} = require("../../../utils/functions/listGetters"); +const { getPagesByListId } = require("../../../utils/functions/pageGetters"); const Answer = require("../Answer"); const { getValueSource } = require("../../builders/valueSource"); @@ -37,7 +40,7 @@ class Question { this.id = `question${question.id}`; this.title = processPipe(ctx)(question.title); if (question.qCode) { - this.q_code = question.qCode.replace(/\s+$/, ''); + this.q_code = question.qCode.trim(); } if (question.descriptionEnabled && question.description) { this.description = [convertPipes(ctx)(question.description)]; @@ -63,14 +66,12 @@ class Question { if (question.answers.some((answer) => answer.repeatingLabelAndInput)) { this.type = "General"; - const list = getList( - ctx, - question.answers[0].repeatingLabelAndInputListId - ) || - getSupplementaryList( - ctx, - question.answers[0].repeatingLabelAndInputListId - ); + const list = + getList(ctx, question.answers[0].repeatingLabelAndInputListId) || + getSupplementaryList( + ctx, + question.answers[0].repeatingLabelAndInputListId + ); this.dynamic_answers = { values: { source: "list", @@ -80,30 +81,31 @@ class Question { answers: this.buildAnswers(question.answers, ctx), }; - const ListCollectorPages = filter(getPagesByListId(ctx, question.answers[0].repeatingLabelAndInputListId), { pageType: "ListCollectorConfirmationPage" }) + const ListCollectorPages = filter( + getPagesByListId(ctx, question.answers[0].repeatingLabelAndInputListId), + { pageType: "ListCollectorConfirmationPage" } + ); if (ListCollectorPages.length) { const expressions = ListCollectorPages.map((page) => ({ - condition: "Unanswered", - left: { - answerId: page.answers[0].id, - type: "Answer" - }, - right: { - optionIds: [ - ] - } - }) - ) + condition: "Unanswered", + left: { + answerId: page.answers[0].id, + type: "Answer", + }, + right: { + optionIds: [], + }, + })); const newSkip = { expressions: expressions, - operator: "And" - } + operator: "And", + }; - if(question.skipConditions) { - question.skipConditions = [newSkip, ...question.skipConditions] - } else { - question.skipConditions = [newSkip] + if (question.skipConditions) { + question.skipConditions = [newSkip, ...question.skipConditions]; + } else { + question.skipConditions = [newSkip]; } } @@ -233,7 +235,7 @@ class Question { }; if (dataVersion !== "3") { if (answer.qCode) { - dateFrom.q_code = answer.qCode.replace(/\s+$/, ''); + dateFrom.q_code = answer.qCode.trim(); } } const dateTo = { @@ -243,7 +245,7 @@ class Question { }; if (dataVersion !== "3") { if (answer.secondaryQCode) { - dateTo.q_code = answer.secondaryQCode.replace(/\s+$/, ''); + dateTo.q_code = answer.secondaryQCode.trim(); } } return [dateFrom, dateTo]; @@ -262,7 +264,7 @@ class Question { ...answer, type: "Checkbox", }; - tempAnswer.options[0].qCode = answer.qCode && answer.qCode.replace(/\s+$/, ''); + tempAnswer.options[0].qCode = answer.qCode && answer.qCode.trim(); delete tempAnswer.qCode; mutuallyExclusiveAnswer = new Answer(tempAnswer, ctx); } else if ( diff --git a/src/utils/HTMLUtils/index.js b/src/utils/HTMLUtils/index.js index e84961b5..029a23d7 100644 --- a/src/utils/HTMLUtils/index.js +++ b/src/utils/HTMLUtils/index.js @@ -20,7 +20,7 @@ const unescapePiping = (value, isMultipleChoiceValue) => { } else { updatedValue = replace(/'/g, `\u2019`, value); } - updatedValue = updatedValue.replace(/\s+$/, ''); //remove trailing spaces + updatedValue = updatedValue.trim(); //remove leading and trailing spaces return updatedValue; }; diff --git a/src/utils/createAnswerCodes/index.js b/src/utils/createAnswerCodes/index.js index 4fa02467..30a49e33 100644 --- a/src/utils/createAnswerCodes/index.js +++ b/src/utils/createAnswerCodes/index.js @@ -59,11 +59,11 @@ const createAnswerCodes = (questionnaireJson) => { if (answer.type === DATE_RANGE) { answerCodes.push({ answer_id: `answer${answer.id}from`, - code: answer.qCode && answer.qCode.replace(/\s+$/, ''), + code: answer.qCode && answer.qCode.trim(), }); answerCodes.push({ answer_id: `answer${answer.id}to`, - code: answer.secondaryQCode && answer.secondaryQCode.replace(/\s+$/, ''), + code: answer.secondaryQCode && answer.secondaryQCode.trim(), }); } // Other answer types output answer ID and answer QCode as their answer codes @@ -71,17 +71,17 @@ const createAnswerCodes = (questionnaireJson) => { if (page && page.pageType === "ListCollectorQualifierPage") { answerCodes.push({ answer_id: `answer${answer.id}`, - code: answer.qCode && answer.qCode.replace(/\s+$/, ''), + code: answer.qCode && answer.qCode.trim(), }); } else if (page && page.pageType === "ListCollectorConfirmationPage") { answerCodes.push({ answer_id: `answer${answer.id}`, - code: answer.qCode && answer.qCode.replace(/\s+$/, ''), + code: answer.qCode && answer.qCode.trim(), }); } else { answerCodes.push({ answer_id: `answer${answer.id}`, - code: answer.qCode && answer.qCode.replace(/\s+$/, ''), + code: answer.qCode && answer.qCode.trim(), }); if ( [RADIO, CHECKBOX, SELECT, MUTUALLY_EXCLUSIVE].includes(answer.type) @@ -93,7 +93,9 @@ const createAnswerCodes = (questionnaireJson) => { ) { answerCodes.push({ answer_id: `answer${option.additionalAnswer.id}`, - code: option.additionalAnswer.qCode && option.additionalAnswer.qCode.replace(/\s+$/, ''), + code: + option.additionalAnswer.qCode && + option.additionalAnswer.qCode.trim(), }); } });