From 41ea648aa34c7d5e8323ced1a5385fff5692da89 Mon Sep 17 00:00:00 2001 From: Henrique Pinheiro Date: Wed, 10 Jan 2024 15:00:04 -0300 Subject: [PATCH] Processa distribution para fauna Closes #57 --- src/fauna.ts | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/fauna.ts b/src/fauna.ts index 8d18f55..8566659 100644 --- a/src/fauna.ts +++ b/src/fauna.ts @@ -20,10 +20,11 @@ type FaunaJson = Record< export const processaFauna = (dwcJson: FaunaJson): FaunaJson => { return Object.fromEntries( Object.entries(dwcJson).reduce((entries, [id, taxon]) => { - // const _distribution = taxon.distribution as Record< - // string, - // Record - // >[] + const distribution = taxon.distribution as { + locality: string + countryCode: string + establishmentMeans: string + }[] if ( !['ESPECIE', 'VARIEDADE', 'FORMA', 'SUB_ESPECIE'].includes( taxon.taxonRank as string @@ -31,18 +32,15 @@ export const processaFauna = (dwcJson: FaunaJson): FaunaJson => { ) { return entries } - // if (distribution) { - // taxon.distribution = { - // origin: distribution[0]?.establishmentMeans, - // Endemism: distribution[0]?.occurrenceRemarks.endemism, - // phytogeographicDomains: - // distribution[0]?.occurrenceRemarks.phytogeographicDomain, - // occurrence: distribution.map(({ locationID }) => locationID).sort(), - // vegetationType: ( - // taxon.speciesprofile as Record>[] - // )?.[0]?.lifeForm?.vegetationType - // } - // } + if (distribution) { + taxon.distribution = { + origin: distribution[0]?.establishmentMeans, + occurrence: distribution[0]?.locality + ?.split(';') + .map((l) => `BR-${l}`), + countryCode: distribution[0]?.countryCode?.split(';') + } + } if (taxon.resourcerelationship) { const resourcerelationship = taxon.resourcerelationship as Record< string,