diff --git a/src/controllers/splinker-controller.js b/src/controllers/splinker-controller.js index 9e7d9ca..07e9e99 100644 --- a/src/controllers/splinker-controller.js +++ b/src/controllers/splinker-controller.js @@ -1,5 +1,7 @@ import { format } from 'date-fns'; +import { converteDecimalParaGrausMinutosSegundos } from '~/helpers/coordenadas'; + import models from '../models'; const { @@ -30,6 +32,7 @@ const obterModeloSPlinkerLotes = async (limit, offset, request, response) => { const tombos = await Tombo.findAll({ limit, offset, + order: [['hcf', 'ASC']], attributes: [ 'data_coleta_mes', 'data_coleta_ano', @@ -134,15 +137,15 @@ const obterModeloSPlinkerLotes = async (limit, offset, request, response) => { }); tombos.forEach(tombo => { - const kingdom = tombo.familia?.reino?.nome || ' '; - const family = tombo.familia?.nome || ' '; - const genus = tombo.genero?.nome || ' '; - const species = tombo.especy?.nome || ' '; - const scientificNameAuthor = tombo.especy?.autor?.nome || ' '; - const commonName = tombo.nomes_populares || ' '; - const catalogNumber = tombo.hcf || ' '; + const kingdom = tombo.familia?.reino?.nome || '\t'; + const family = tombo.familia?.nome || '\t'; + const genus = tombo.genero?.nome || '\t'; + const species = tombo.especy?.nome || '\t'; + const scientificNameAuthor = tombo.especy?.autor?.nome || '\t'; + const commonName = tombo.nomes_populares || '\t'; + const catalogNumber = tombo.hcf || '\t'; const basisOfRecord = 'PreservedSpecimen'; - const typeStatus = tombo.tipo ? tombo.tipo?.nome : ' '; + const typeStatus = tombo.tipo ? tombo.tipo?.nome : '\t'; const collectionDate = [ tombo.data_coleta_ano, tombo.data_coleta_mes?.toString().padStart(2, '0'), @@ -150,15 +153,19 @@ const obterModeloSPlinkerLotes = async (limit, offset, request, response) => { ] .filter(Boolean) .join('-'); - const collectorName = tombo.coletore?.nome || ' '; - const collectorNumber = tombo.numero_coleta || ' '; - const country = tombo.locais_coletum?.cidade?.estado?.paise?.nome || ' '; - const stateOrProvince = tombo.locais_coletum?.cidade?.estado?.sigla || ' '; - const city = tombo.locais_coletum?.cidade?.nome || ' '; - const locality = tombo.locais_coletum?.descricao || ' '; - const latitude = tombo.latitude || ' '; - const longitude = tombo.longitude || ' '; - const elevation = tombo.altitude || ' '; + const collectorName = tombo.coletore?.nome || '\t'; + const collectorNumber = tombo.numero_coleta || '\t'; + const country = tombo.locais_coletum?.cidade?.estado?.paise?.nome || '\t'; + const stateOrProvince = tombo.locais_coletum?.cidade?.estado?.sigla || '\t'; + const city = tombo.locais_coletum?.cidade?.nome || '\t'; + const locality = tombo.locais_coletum?.descricao || '\t'; + const latitude = tombo.latitude + ? converteDecimalParaGrausMinutosSegundos(tombo.latitude, false, true) + : '\t'; + const longitude = tombo.longitude + ? converteDecimalParaGrausMinutosSegundos(tombo.longitude, true, true) + : '\t'; + const elevation = tombo.altitude + ' m' || '\t'; const identificationDate = [ tombo.data_identificacao_ano, tombo.data_identificacao_mes?.toString().padStart(2, '0'), @@ -168,35 +175,35 @@ const obterModeloSPlinkerLotes = async (limit, offset, request, response) => { .join('-'); const identifierName = tombo.identificadores ? tombo.identificadores.map(i => i.nome).join(', ') - : ' '; + : '\t'; const notes = tombo.tombos_fotos?.length > 0 - ? `${tombo.tombos_fotos.map(foto => `[BARCODE=${foto.codigo_barra}]`).join(' , ')} ${tombo.observacao || ' '}` - : tombo.observacao || ' '; + ? `${tombo.tombos_fotos.map(foto => `[BARCODE=${foto.codigo_barra}]`).join(' , ')} ${tombo.observacao || '\t'}` + : tombo.observacao || '\t'; const linha = [ kingdom, - ' ', // Phylum - ' ', // Class - ' ', // Order + '\t', // Phylum + '\t', // Class + '\t', // Order family, genus, species, - ' ', // Subspecies + '\t', // Subspecies scientificNameAuthor, commonName, - ' ', // Field number + '\t', // Field number catalogNumber, - ' ', // Previous catalog number + '\t', // Previous catalog number basisOfRecord, typeStatus, - ' ', // Preparation type - ' ', // Individual count - ' ', // Specimen sex - ' ', // Specimen life stage + '\t', // Preparation type + '\t', // Individual count + '\t', // Specimen sex + '\t', // Specimen life stage collectionDate, collectorName, collectorNumber, - ' ', // Continent or Ocean + '\t', // Continent or Ocean country, stateOrProvince, city, @@ -204,11 +211,11 @@ const obterModeloSPlinkerLotes = async (limit, offset, request, response) => { latitude, longitude, elevation, - ' ', // Depth + '\t', // Depth identificationDate, identifierName, - ' ', // Related catalog item - ' ', // Relationship type + '\t', // Related catalog item + '\t', // Relationship type notes, ].join('|');