From 91d13ae83f8eaf8b4487bba332f313ae5e24df57 Mon Sep 17 00:00:00 2001 From: Lucas Vaz Date: Tue, 17 Mar 2026 21:38:25 -0300 Subject: [PATCH 1/4] Corrigindo a ficha tombo com a listagem dos identificadores --- src/controllers/fichas-tombos-controller.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/controllers/fichas-tombos-controller.js b/src/controllers/fichas-tombos-controller.js index 0addb97..12f97bc 100644 --- a/src/controllers/fichas-tombos-controller.js +++ b/src/controllers/fichas-tombos-controller.js @@ -235,9 +235,16 @@ export default function fichaTomboController(request, response, next) { const dataTombo = new Date(tombo.data_tombo); const romanoDataTombo = (`${dataTombo.getDate()}/${romanos[dataTombo.getMonth()]}/${dataTombo.getFullYear()}`); - const identificador = tombo.identificadores?.[0]?.nome - && tombo.identificadores?.[0]?.nome.toLowerCase() !== 'não-identificado' - ? tombo.identificadores?.[0]?.nome + const identificador = tombo.identificadores && tombo.identificadores.length > 0 + ? tombo.identificadores + .filter(ident => ident.nome && ident.nome.toLowerCase() !== 'não-identificado') + .sort((a, b) => { + const ordemA = a.tombos_identificadores?.ordem || 0; + const ordemB = b.tombos_identificadores?.ordem || 0; + return ordemA - ordemB; + }) + .map(ident => ident.nome) + .join('; ') : ''; const romanoDataIdentificacao = formataDataIdentificacao( From 84e74ecc18ed2adfddad4ba12adff6c772d5f7fc Mon Sep 17 00:00:00 2001 From: Lucas Vaz Date: Tue, 17 Mar 2026 22:15:42 -0300 Subject: [PATCH 2/4] feat: Adicionando a listagem pela busca de tombos pelo codigo de barra da image --- src/controllers/tombos-controller.js | 85 ++++++++++++++-------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/src/controllers/tombos-controller.js b/src/controllers/tombos-controller.js index 671ac3f..91b54e5 100644 --- a/src/controllers/tombos-controller.js +++ b/src/controllers/tombos-controller.js @@ -681,48 +681,44 @@ export const desativar = (request, response, next) => { export const listagem = (request, response, next) => { const { pagina, limite, offset } = request.paginacao; const { - nome_cientifico: nomeCientifico, hcf, tipo, nome_popular: nomePopular, situacao, + nome_cientifico: nomeCientifico, + hcf, + tipo, + nome_popular: nomePopular, + situacao, + codigo_barra_foto } = request.query; + let where = { rascunho: false, }; - if (nomeCientifico) { - where = { - ...where, - nome_cientifico: { [Op.iLike]: `%${nomeCientifico}%` }, - }; - } + if (nomeCientifico) { where.nome_cientifico = { [Op.iLike]: `%${nomeCientifico}%` }; } + if (hcf) { where.hcf = hcf; } + if (tipo) { where.tipo_id = tipo; } + if (nomePopular) { where.nomes_populares = { [Op.iLike]: `%${nomePopular}%` }; } + if (situacao) { where.situacao = situacao; } - if (hcf) { - where = { - ...where, - hcf, - }; - } - - if (tipo) { - where = { - ...where, - tipo_id: tipo, - }; - } - - if (nomePopular) { - where = { - ...where, - nomes_populares: { [Op.iLike]: `%${nomePopular}%` }, - }; - } + let include = [ + { + model: Coletor, + attributes: ['id', 'nome'], + required: false, + } + ]; - if (situacao) { - where = { - ...where, - situacao, - }; + if (codigo_barra_foto) { + include.push({ + model: TomboFoto, + where: { + codigo_barra: codigo_barra_foto + }, + attributes: ['id', 'codigo_barra', 'tombo_hcf'], + required: true + }); } - let retorno = { // eslint-disable-line + let retorno = { metadados: { total: 0, pagina, @@ -730,12 +726,17 @@ export const listagem = (request, response, next) => { }, tombos: [], }; + Promise.resolve() - .then(() => Tombo.count({ where })) + .then(() => Tombo.count({ + where, + include: codigo_barra_foto ? include : [], + distinct: true + })) .then(total => { retorno.metadados.total = total; }) - .then(() => Tombo.findAndCountAll({ + .then(() => Tombo.findAll({ attributes: [ 'hcf', 'nomes_populares', @@ -744,21 +745,19 @@ export const listagem = (request, response, next) => { 'data_coleta_mes', 'data_coleta_ano', 'created_at', + 'coletor_id', + 'tipo_id', ], - include: { - model: Coletor, - attributes: ['id', 'nome'], - required: false, - }, + include, where, + subQuery: false, order: [['hcf', 'DESC']], limit: limite, offset, })) .then(listaTombos => { - retorno.tombos = listaTombos.rows; - response.status(codigos.LISTAGEM) - .json(retorno); + retorno.tombos = listaTombos; + response.status(codigos.LISTAGEM).json(retorno); }) .catch(next); }; From b57b2839e2da1835c2a51edcf846fd7da6f1d9bf Mon Sep 17 00:00:00 2001 From: Lucas Vaz Date: Tue, 17 Mar 2026 22:36:01 -0300 Subject: [PATCH 3/4] lint fix --- src/controllers/fichas-tombos-controller.js | 16 ++++++------- src/controllers/tombos-controller.js | 26 ++++++++++----------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/controllers/fichas-tombos-controller.js b/src/controllers/fichas-tombos-controller.js index 12f97bc..9a08b35 100644 --- a/src/controllers/fichas-tombos-controller.js +++ b/src/controllers/fichas-tombos-controller.js @@ -237,14 +237,14 @@ export default function fichaTomboController(request, response, next) { const identificador = tombo.identificadores && tombo.identificadores.length > 0 ? tombo.identificadores - .filter(ident => ident.nome && ident.nome.toLowerCase() !== 'não-identificado') - .sort((a, b) => { - const ordemA = a.tombos_identificadores?.ordem || 0; - const ordemB = b.tombos_identificadores?.ordem || 0; - return ordemA - ordemB; - }) - .map(ident => ident.nome) - .join('; ') + .filter(ident => ident.nome && ident.nome.toLowerCase() !== 'não-identificado') + .sort((a, b) => { + const ordemA = a.tombos_identificadores?.ordem || 0; + const ordemB = b.tombos_identificadores?.ordem || 0; + return ordemA - ordemB; + }) + .map(ident => ident.nome) + .join('; ') : ''; const romanoDataIdentificacao = formataDataIdentificacao( diff --git a/src/controllers/tombos-controller.js b/src/controllers/tombos-controller.js index 91b54e5..4987103 100644 --- a/src/controllers/tombos-controller.js +++ b/src/controllers/tombos-controller.js @@ -681,12 +681,12 @@ export const desativar = (request, response, next) => { export const listagem = (request, response, next) => { const { pagina, limite, offset } = request.paginacao; const { - nome_cientifico: nomeCientifico, - hcf, - tipo, - nome_popular: nomePopular, + nome_cientifico: nomeCientifico, + hcf, + tipo, + nome_popular: nomePopular, situacao, - codigo_barra_foto + codigo_barra_foto, } = request.query; let where = { @@ -704,17 +704,17 @@ export const listagem = (request, response, next) => { model: Coletor, attributes: ['id', 'nome'], required: false, - } + }, ]; if (codigo_barra_foto) { include.push({ model: TomboFoto, where: { - codigo_barra: codigo_barra_foto + codigo_barra: codigo_barra_foto, }, attributes: ['id', 'codigo_barra', 'tombo_hcf'], - required: true + required: true, }); } @@ -728,15 +728,15 @@ export const listagem = (request, response, next) => { }; Promise.resolve() - .then(() => Tombo.count({ - where, - include: codigo_barra_foto ? include : [], - distinct: true + .then(() => Tombo.count({ + where, + include: codigo_barra_foto ? include : [], + distinct: true, })) .then(total => { retorno.metadados.total = total; }) - .then(() => Tombo.findAll({ + .then(() => Tombo.findAll({ attributes: [ 'hcf', 'nomes_populares', From e8bb8b9c5fa9100ac55cc208982c836d16237817 Mon Sep 17 00:00:00 2001 From: Lucas Vaz Date: Tue, 17 Mar 2026 22:41:34 -0300 Subject: [PATCH 4/4] lint fix --- src/controllers/tombos-controller.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/controllers/tombos-controller.js b/src/controllers/tombos-controller.js index 4987103..552831c 100644 --- a/src/controllers/tombos-controller.js +++ b/src/controllers/tombos-controller.js @@ -693,11 +693,21 @@ export const listagem = (request, response, next) => { rascunho: false, }; - if (nomeCientifico) { where.nome_cientifico = { [Op.iLike]: `%${nomeCientifico}%` }; } - if (hcf) { where.hcf = hcf; } - if (tipo) { where.tipo_id = tipo; } - if (nomePopular) { where.nomes_populares = { [Op.iLike]: `%${nomePopular}%` }; } - if (situacao) { where.situacao = situacao; } + if (nomeCientifico) { + where.nome_cientifico = { [Op.iLike]: `%${nomeCientifico}%` }; + } + if (hcf) { + where.hcf = hcf; + } + if (tipo) { + where.tipo_id = tipo; + } + if (nomePopular) { + where.nomes_populares = { [Op.iLike]: `%${nomePopular}%` }; + } + if (situacao) { + where.situacao = situacao; + } let include = [ {