@gouvfr-anct/lieux-de-mediation-numerique
Version:
📚 Bibliothèque pour la modélisation des lieux de médiation numérique respectant le standard du schéma de données des lieux de médiation numériques
52 lines (51 loc) • 2.96 kB
JavaScript
import { isValidTelephone, isValidCourriel } from '../../../models';
export const isServiceWithAdresse = (service) => service.adresse != null && service.commune != null && service.code_postal != null;
const hasCodeInsee = (service) => service.code_insee == null && service._di_geocodage_code_insee == null;
const adresseFromService = (service) => ({
commune: service.commune,
code_postal: service.code_postal,
adresse: service.adresse,
...(hasCodeInsee(service) ? {} : { code_insee: service.code_insee ?? service._di_geocodage_code_insee }),
...(service.complement_adresse == null ? {} : { complement_adresse: service.complement_adresse })
});
const presentationFromStructure = (structure) => ({
...(structure.presentation_resume == null ? {} : { presentation_resume: structure.presentation_resume }),
...(structure.presentation_detail == null ? {} : { presentation_detail: structure.presentation_detail })
});
const contactFromServiceOrStructure = (service, structure) => ({
...(structure.telephone == null ? {} : { telephone: structure.telephone }),
...(structure.courriel == null ? {} : { courriel: structure.courriel }),
...(isValidTelephone(service.telephone ?? '') ? { telephone: service.telephone } : {}),
...(isValidCourriel(service.courriel ?? '') ? { courriel: service.courriel } : {})
});
const labelsFromStructure = (structure) => ({
...(structure.labels_nationaux == null ? {} : { labels_nationaux: structure.labels_nationaux }),
...(structure.labels_autres == null ? {} : { labels_autres: structure.labels_autres })
});
const generalFieldsFromServiceAndStructure = (service, structure) => ({
id: service.id,
nom: service.nom,
...(structure.siret == null ? {} : { siret: structure.siret }),
...(structure.typologie == null ? {} : { typologie: structure.typologie }),
structure_parente: service.structure_id,
...(structure.accessibilite == null ? {} : { accessibilite: structure.accessibilite }),
...(structure.site_web == null ? {} : { site_web: structure.site_web })
});
const collecteFieldsFromServiceAndStructure = (service, structure) => ({
date_maj: service.date_maj ?? structure.date_maj,
source: service.source
});
const localisationFieldsFromService = (service) => ({
...(service.latitude == null ? {} : { latitude: service.latitude }),
...(service.longitude == null ? {} : { longitude: service.longitude })
});
export const toStructureDataInclusion = (service, structure) => ({
...generalFieldsFromServiceAndStructure(service, structure),
...collecteFieldsFromServiceAndStructure(service, structure),
...localisationFieldsFromService(service),
...adresseFromService(service),
...presentationFromStructure(structure),
...contactFromServiceOrStructure(service, structure),
...labelsFromStructure(structure),
...(structure.horaires_ouverture == null ? {} : { horaires_ouverture: structure.horaires_ouverture })
});