Skip to content

Commit

Permalink
added section getters function
Browse files Browse the repository at this point in the history
Signed-off-by: sudeep <[email protected]>
  • Loading branch information
sudeepkunhis committed Jun 12, 2024
1 parent acc3631 commit d444126
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/eq_schema/schema/Question/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const { getPagesByListId } = require("../../../utils/functions/pageGetters");
const Answer = require("../Answer");
const { getValueSource } = require("../../builders/valueSource");

const {
getSectionByPageId,
} = require("../../../utils/functions/sectionGetters");

const {
DATE,
DATE_RANGE,
Expand All @@ -39,22 +43,6 @@ const processPipe = (ctx, isMultipleChoiceValue = false, isRepeatingSection) =>
const reversePipe = (ctx) =>
flow(wrapContents("contents"), reversePipeContent(ctx));

const getSectionByPageId = (ctx, pageId) => {
let result;
if (ctx && ctx.questionnaireJson && ctx.questionnaireJson.sections) {
ctx.questionnaireJson.sections.forEach((section) => {
section.folders.forEach((folder) => {
folder.pages.forEach((page) => {
if (page.id === pageId) {
result = section;
}
});
});
});
}
return result;
};

class Question {
constructor(question, ctx) {
this.id = `question${question.id}`;
Expand Down
17 changes: 17 additions & 0 deletions src/utils/functions/sectionGetters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const getSectionByPageId = (ctx, pageId) => {
let result;
if (ctx && ctx.questionnaireJson && ctx.questionnaireJson.sections) {
ctx.questionnaireJson.sections.forEach((section) => {
section.folders.forEach((folder) => {
folder.pages.forEach((page) => {
if (page.id === pageId) {
result = section;
}
});
});
});
}
return result;
};

module.exports = { getSectionByPageId };

0 comments on commit d444126

Please sign in to comment.