Skip to content

Commit 45b3f2f

Browse files
authored
prod release (#277)
2 parents 9905c26 + bc72ee4 commit 45b3f2f

15 files changed

Lines changed: 329 additions & 118 deletions

public/js/ficha-tombo.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
window.addEventListener('load', () => {
2+
const svg = document.querySelector('[id^="code128_"]');
3+
if (!svg) return;
4+
5+
if (typeof JsBarcode !== 'function') {
6+
console.error('JsBarcode não carregado. Verifique o caminho do script e a CSP.');
7+
return;
8+
}
9+
const attr = svg.getAttribute('data-codigo-barras');
10+
const id = svg.id;
11+
const cbarra = attr || '';
12+
JsBarcode('#'.concat(id), cbarra, { margin: 0, width: 1.4, height: 40, fontSize: 10 });
13+
14+
15+
if (!/standalone/.test(window.location.href)) {
16+
window.print();
17+
}
18+
});

src/controllers/cidades-controller.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,17 @@ export const listaTodosCidades = where =>
147147
export const listagem = (request, response, next) => {
148148
let where = {};
149149

150-
if (request.query.id !== undefined) {
150+
if (request.query.estado_id !== undefined) {
151151
where = {
152-
estado_id: request.query.id,
152+
...where,
153+
estado_id: request.query.estado_id,
154+
};
155+
}
156+
157+
if (request.query.nome) {
158+
where = {
159+
...where,
160+
nome: { [Op.like]: `%${request.query.nome}%` },
153161
};
154162
}
155163

src/controllers/estados-controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import BadRequestException from '../errors/bad-request-exception';
44
import models from '../models';
55
import codigos from '../resources/codigos-http';
66

7+
const { Op } = require('sequelize');
8+
79
const {
810
Estado,
911
Pais,
@@ -68,12 +70,17 @@ export const cadastrarEstado = (req, res, next) => {
6870
export const listagem = async (req, res, next) => {
6971
try {
7072
const paisId = req.query.pais_id ? parseInt(req.query.pais_id, 10) : undefined;
73+
const { nome } = req.query;
7174

7275
const where = {};
7376
if (!Number.isNaN(paisId) && paisId !== undefined) {
7477
where.pais_id = paisId;
7578
}
7679

80+
if (nome) {
81+
where.nome = { [Op.like]: `%${nome}%` };
82+
}
83+
7784
const estados = await Estado.findAll({
7885
attributes: { exclude: ['created_at', 'updated_at'] },
7986
include: [{ model: Pais, as: 'pais', attributes: ['id', 'nome', 'sigla'] }],

src/controllers/locais-coleta-controller.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,19 @@ export const cadastrarVegetacao = (request, response, next) => {
8787
};
8888

8989
export const buscarRelevos = (request, response, next) => {
90+
let where = {};
91+
92+
if (request.query.nome) {
93+
where = {
94+
...where,
95+
nome: { [sequelize.Op.like]: `%${request.query.nome}%` },
96+
};
97+
}
98+
9099
Promise.resolve()
91100
.then(() => Relevo.findAndCountAll({
92101
attributes: ['id', 'nome'],
102+
where,
93103
order: [['nome', 'ASC']],
94104
}))
95105
.then(relevos => {
@@ -99,9 +109,19 @@ export const buscarRelevos = (request, response, next) => {
99109
};
100110

101111
export const buscarSolos = (request, response, next) => {
112+
let where = {};
113+
114+
if (request.query.nome) {
115+
where = {
116+
...where,
117+
nome: { [sequelize.Op.like]: `%${request.query.nome}%` },
118+
};
119+
}
120+
102121
Promise.resolve()
103122
.then(() => Solo.findAndCountAll({
104123
attributes: ['id', 'nome'],
124+
where,
105125
order: [['nome', 'ASC']],
106126
}))
107127
.then(solos => {
@@ -111,9 +131,19 @@ export const buscarSolos = (request, response, next) => {
111131
};
112132

113133
export const buscarVegetacoes = (request, response, next) => {
134+
let where = {};
135+
136+
if (request.query.nome) {
137+
where = {
138+
...where,
139+
nome: { [sequelize.Op.like]: `%${request.query.nome}%` },
140+
};
141+
}
142+
114143
Promise.resolve()
115144
.then(() => Vegetacao.findAndCountAll({
116145
attributes: ['id', 'nome'],
146+
where,
117147
order: [['nome', 'ASC']],
118148
}))
119149
.then(vegetacoes => {
@@ -134,7 +164,7 @@ export const cadastrarLocalColeta = async (request, response, next) => {
134164

135165
export const buscarLocaisColeta = async (request, response, next) => {
136166
try {
137-
const { cidade_id: cidadeId, estado_id: estadoId, pais_id: paisId } = request.query;
167+
const { cidade_id: cidadeId, estado_id: estadoId, pais_id: paisId, descricao } = request.query;
138168
const { limite, pagina, offset } = request.paginacao;
139169
const { getAll } = request.query;
140170

@@ -152,6 +182,10 @@ export const buscarLocaisColeta = async (request, response, next) => {
152182
{ model: FaseSucessional },
153183
];
154184

185+
if (descricao) {
186+
where.descricao = { [sequelize.Op.like]: `%${descricao}%` };
187+
}
188+
155189
if (cidadeId) {
156190
where.cidade_id = cidadeId;
157191
} else if (estadoId) {

src/controllers/paises-controller.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@ const {
55
Estado,
66
} = models;
77

8-
export const listaTodosPaises = () => Pais.findAndCountAll({
8+
const { Op } = require('sequelize');
9+
10+
export const listaTodosPaises = where => Pais.findAndCountAll({
911
attributes: {
1012
exclude: ['updated_at', 'created_at'],
1113
},
14+
where,
1215
});
1316

1417
export const listagem = (request, response, next) => {
18+
let where = {};
19+
20+
if (request.query.nome) {
21+
where = {
22+
...where,
23+
nome: { [Op.like]: `%${request.query.nome}%` },
24+
};
25+
}
26+
1527
Promise.resolve()
16-
.then(() => listaTodosPaises())
28+
.then(() => listaTodosPaises(where))
1729
.then(paises => {
1830
response.status(200).json(paises.rows);
1931
})

src/controllers/relatorios-controller.js

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,21 @@ export const obtemDadosDoRelatorioDeColetaPorLocalEIntervaloDeData = async (req,
182182
attributes: ['hcf', 'numero_coleta', 'nome_cientifico', 'data_coleta_ano', 'data_coleta_mes', 'data_coleta_dia'],
183183
where: whereData,
184184
include: [
185+
{
186+
model: Familia,
187+
attributes: ['id', 'nome'],
188+
// required: true,
189+
},
190+
{
191+
model: Genero,
192+
attributes: ['id', 'nome'],
193+
// required: true,
194+
},
185195
{
186196
model: Especie,
187197
attributes: ['id', 'nome'],
188-
required: true,
198+
// required: true,
189199
include: [
190-
{
191-
model: Genero,
192-
attributes: ['id', 'nome'],
193-
},
194-
{
195-
model: Familia,
196-
attributes: ['id', 'nome'],
197-
required: true,
198-
},
199200
{
200201
model: Autor,
201202
attributes: ['id', 'nome'],
@@ -214,13 +215,15 @@ export const obtemDadosDoRelatorioDeColetaPorLocalEIntervaloDeData = async (req,
214215
});
215216

216217
if (req.method === 'GET') {
218+
const dadosPuros = tombos.rows.map(registro => registro.get({ plain: true }));
219+
217220
res.json({
218221
metadados: {
219-
total: tombos.count,
222+
total: dadosPuros?.length,
220223
pagina,
221224
limite,
222225
},
223-
resultado: formatarDadosParaRelatorioDeColetaPorLocalEIntervaloDeData(tombos),
226+
resultado: formatarDadosParaRelatorioDeColetaPorLocalEIntervaloDeData(dadosPuros),
224227
filtro: formataTextFilter(local, dataInicio, dataFim || new Date()),
225228
});
226229
return;
@@ -502,24 +505,33 @@ export const obtemDadosDoRelatorioDeLocalDeColeta = async (req, res, next) => {
502505

503506
try {
504507
const tombos = await Tombo.findAndCountAll({
505-
attributes: ['hcf', 'numero_coleta', 'nome_cientifico', 'data_coleta_ano', 'data_coleta_mes', 'data_coleta_dia'],
508+
attributes: [
509+
'hcf',
510+
'numero_coleta',
511+
'familia_id',
512+
'especie_id',
513+
'genero_id',
514+
'nome_cientifico',
515+
'data_coleta_ano',
516+
'data_coleta_mes',
517+
'data_coleta_dia',
518+
],
506519
where: whereData,
507520
include: [
521+
{
522+
model: Familia,
523+
attributes: ['id', 'nome'],
524+
// required: true,
525+
},
526+
{
527+
model: Genero,
528+
attributes: ['id', 'nome'],
529+
// required: true,
530+
},
508531
{
509532
model: Especie,
510533
attributes: ['id', 'nome'],
511-
required: true,
512-
include: [
513-
{
514-
model: Genero,
515-
attributes: ['id', 'nome'],
516-
},
517-
{
518-
model: Familia,
519-
attributes: ['id', 'nome'],
520-
required: true,
521-
},
522-
],
534+
// required: true,
523535
},
524536
{
525537
model: LocalColeta,

0 commit comments

Comments
 (0)