Skip to content

Commit

Permalink
Merge pull request #130 from ONSdigital/EAR-1883-metadata-logic
Browse files Browse the repository at this point in the history
EAR 1883 Add metadata logic
  • Loading branch information
farres1 authored Dec 21, 2022
2 parents 6eb8ad2 + 3ab0da6 commit c1df3b9
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 165 deletions.
51 changes: 30 additions & 21 deletions src/eq_schema/builders/basicQuestionnaireJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ const questionnaireJson = {
id: "1",
title: "Basic Questionnaire JSON",
summary: false,
metadata: [
{
id: "metadata-1",
key: "ru_name",
alias: "Ru Name",
type: "Text",
textValue: "ESSENTIAL ENTERPRISE LTD.",
},
],
sections: [
{
id: "1",
Expand All @@ -21,9 +30,9 @@ const questionnaireJson = {
{
id: "1",
type: "Currency",
label: "Answer 1"
}
]
label: "Answer 1",
},
],
},
{
id: "2",
Expand All @@ -35,13 +44,13 @@ const questionnaireJson = {
{
id: "2",
type: "Number",
label: "Answer 2"
}
]
}
]
}
]
label: "Answer 2",
},
],
},
],
},
],
},
{
id: "2",
Expand All @@ -61,7 +70,7 @@ const questionnaireJson = {
{
id: "3",
type: "Number",
label: "Answer 3"
label: "Answer 3",
},
{
id: "4",
Expand All @@ -74,16 +83,16 @@ const questionnaireJson = {
{
id: "456",
label: "white",
}
]
}
]
}
]
}
]
}
]
},
],
},
],
},
],
},
],
},
],
};

const questionnaireJsonWithSummary = {
Expand Down
22 changes: 22 additions & 0 deletions src/eq_schema/builders/routing2/newRoutingDestination/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const routingConditionConversion = require("../../../../utils/routingConditionConversion");
const {
getMetadataKey,
} = require("../../../../utils/contentUtils/getMetadataKey");

const { flatMap, filter } = require("lodash");

const authorConditions = {
Expand Down Expand Up @@ -35,6 +39,10 @@ const checkType = (type) => {
return "answers";
}

if (type === "Metadata") {
return "metadata";
}

return null;
};

Expand Down Expand Up @@ -150,9 +158,23 @@ const buildAnswerObject = (
return finalVal;
};

const buildMetadataObject = (expression, ctx) => {
const { condition, left, right } = expression;
const returnValue = [
{
source: checkType(left.type),
identifier: getMetadataKey(ctx, left.metadataId),
},
right.customValue.text,
];
return { [routingConditionConversion(condition)]: returnValue };
};

const checkValidRoutingType = (expression, ctx) => {
if (expression.left.type === "Answer") {
return buildAnswerObject(expression, ctx);
} else if (expression.left.type === "Metadata") {
return buildMetadataObject(expression, ctx);
} else {
throw new Error(
`${expression.left.type} is not a valid routing answer type`
Expand Down
Loading

0 comments on commit c1df3b9

Please sign in to comment.