@gouvfr-anct/mednum
Version:
✨ Permet de transformer une source de données vers le schéma des lieux de mediation numerique
26 lines (25 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processFormationsLabels = void 0;
const lieux_de_mediation_numerique_1 = require("@gouvfr-anct/lieux-de-mediation-numerique");
const input_1 = require("../../input");
const isAllowedTerm = (choice, sourceValue) => choice.sauf?.every((forbidden) => !sourceValue.includes(forbidden)) ?? true;
const isTermFound = (sourceValue, choice) => (found, term) => found || (sourceValue.includes(term.toLowerCase()) && isAllowedTerm(choice, sourceValue));
const containsOneOfTheTerms = (choice, sourceValue = '') => choice.termes == null ? sourceValue !== '' : choice.termes.reduce(isTermFound(sourceValue.toLowerCase(), choice), false);
const appendFormationLabel = (formationsLabels, formationLabel) => [
...formationsLabels,
...(formationLabel == null ? [] : [formationLabel])
];
const isDefault = (choice) => choice.colonnes == null;
const findAndAppendFormationsLabels = (choice, source) => (formationsLabels, colonne) => containsOneOfTheTerms(choice, source[colonne]?.toString())
? appendFormationLabel(formationsLabels, choice.cible)
: formationsLabels;
const formationsLabelsForTerms = (choice, source) => (formationsLabels, colonne) => isDefault(choice)
? appendFormationLabel(formationsLabels, choice.cible)
: findAndAppendFormationsLabels(choice, source)(formationsLabels, colonne);
const appendFormationsLabels = (source) => (formationsLabels, choice) => [
...formationsLabels,
...(choice.colonnes ?? (0, input_1.cibleAsDefault)(choice)).reduce(formationsLabelsForTerms(choice, source), [])
];
const processFormationsLabels = (source, matching) => (0, lieux_de_mediation_numerique_1.FormationsLabels)(Array.from(new Set(matching.formations_labels?.reduce(appendFormationsLabels(source), []))));
exports.processFormationsLabels = processFormationsLabels;