Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 41 additions & 34 deletions src/controllers/splinker-controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { format } from 'date-fns';

import { converteDecimalParaGrausMinutosSegundos } from '~/helpers/coordenadas';

import models from '../models';

const {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -134,31 +137,35 @@ 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'),
tombo.data_coleta_dia?.toString().padStart(2, '0'),
]
.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'),
Expand All @@ -168,47 +175,47 @@ 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,
locality,
latitude,
longitude,
elevation,
' ', // Depth
'\t', // Depth
identificationDate,
identifierName,
' ', // Related catalog item
' ', // Relationship type
'\t', // Related catalog item
'\t', // Relationship type
notes,
].join('|');

Expand Down
Loading