UNPKG

@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

57 lines (56 loc) • 3.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toStructureDataInclusion = exports.isServiceWithAdresse = void 0; const models_1 = require("../../../models"); const isServiceWithAdresse = (service) => service.adresse != null && service.commune != null && service.code_postal != null; exports.isServiceWithAdresse = isServiceWithAdresse; 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 }), ...((0, models_1.isValidTelephone)(service.telephone ?? '') ? { telephone: service.telephone } : {}), ...((0, models_1.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 }) }); 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 }) }); exports.toStructureDataInclusion = toStructureDataInclusion;