UNPKG

@gouvfr-anct/mednum

Version:

✨ Permet de transformer une source de données vers le schéma des lieux de mediation numerique

21 lines (20 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processFraisACharge = 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 appendFrais = (fraisACharge, frais) => [...fraisACharge, ...(frais == null ? [] : [frais])]; const isDefault = (choice) => choice.colonnes == null; const findAndAppendFraisACharge = (choice, source) => (fraisACharge, colonne) => containsOneOfTheTerms(choice, source[colonne]?.toString()) ? appendFrais(fraisACharge, choice.cible) : fraisACharge; const fraisAChargeForTerms = (choice, source) => (fraisACharge, colonne) => isDefault(choice) ? appendFrais(fraisACharge, choice.cible) : findAndAppendFraisACharge(choice, source)(fraisACharge, colonne); const appendFraisACharge = (source) => (fraisACharge, choice) => [ ...fraisACharge, ...(choice.colonnes ?? (0, input_1.cibleAsDefault)(choice)).reduce(fraisAChargeForTerms(choice, source), []) ]; const processFraisACharge = (source, matching) => (0, lieux_de_mediation_numerique_1.FraisACharge)(Array.from(new Set(matching.frais_a_charge?.reduce(appendFraisACharge(source), [])))); exports.processFraisACharge = processFraisACharge;