Skip to content

Commit

Permalink
Schema summary: added validation_message_LANG columns
Browse files Browse the repository at this point in the history
  • Loading branch information
SteRiccio committed Nov 13, 2024
1 parent 7dc1245 commit f8cc580
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions server/modules/survey/service/schemaSummary/schemaSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ const getValidationsSummary = ({ nodeDef }) => {
.join('\n')
}

const getValidationMessages = ({ nodeDef, lang }) => {
const validations = NodeDef.getValidations(nodeDef)
const expressions = NodeDefValidations.getExpressions(validations)
return expressions
.reduce((acc, expression) => {
const message = NodeDefExpression.getMessage(lang)(expression)
if (message) {
acc.push(message)
}
return acc
}, [])
.join('\n')
}

export const generateSchemaSummaryItems = async ({ surveyId, cycle }) => {
const survey = await SurveyManager.fetchSurveyAndNodeDefsBySurveyId({ surveyId, draft: true, advanced: true })
const nodeDefs = []
Expand Down Expand Up @@ -141,6 +155,14 @@ export const generateSchemaSummaryItems = async ({ surveyId, cycle }) => {
minCount: String(NodeDefValidations.getMinCount(NodeDef.getValidations(nodeDef))),
maxCount: String(NodeDefValidations.getMaxCount(NodeDef.getValidations(nodeDef))),
validations: getValidationsSummary({ nodeDef }),
// validation messages
...languages.reduce(
(acc, lang) => ({
...acc,
[`validation_message_${lang}`]: getValidationMessages({ nodeDef, lang }),
}),
{}
),
cycle: String(NodeDef.getCycles(nodeDef).map(RecordCycle.getLabel)), // this is to show the user the value that they see into the UI -> https://github.com/openforis/arena/issues/1677
}
})
Expand Down

0 comments on commit f8cc580

Please sign in to comment.