Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions src/controllers/relatorios-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
// Transforma os valores em uma data e compara com o intervalo
Sequelize.where(
dateExpr,
{ [Op.between]: [dataInicio, dataFim ?? new Date()] }

Check failure on line 181 in src/controllers/relatorios-controller.js

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
),
],
};
Expand Down Expand Up @@ -279,17 +279,17 @@
});
}
whereData = {
[Op.and]: [

Check failure on line 282 in src/controllers/relatorios-controller.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 12 spaces but found 10
Sequelize.where(

Check failure on line 283 in src/controllers/relatorios-controller.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 16 spaces but found 12
literal(`

Check failure on line 284 in src/controllers/relatorios-controller.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 20 spaces but found 14
make_date(
(data_coleta_ano)::int,
COALESCE(NULLIF(data_coleta_mes, 0), 1)::int,
COALESCE(NULLIF(data_coleta_dia, 0), 1)::int
)
`),
{

Check failure on line 291 in src/controllers/relatorios-controller.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 20 spaces but found 14
[Op.between]: [

Check failure on line 292 in src/controllers/relatorios-controller.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 24 spaces but found 16
Sequelize.literal(`TO_DATE('${dataInicio.slice(0, 10)}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim || new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
],
Expand Down Expand Up @@ -497,7 +497,7 @@
const { limite, pagina, offset } = paginacao;
const { local, dataInicio, dataFim } = req.query;

let whereLocal = {};
const whereLocal = {};
let whereData = {};
if (dataInicio) {
if (dataFim && isBefore(new Date(dataFim), new Date(dataInicio))) {
Expand Down Expand Up @@ -592,7 +592,7 @@
const dadosFormatados = agruparPorLocal(dadosPuros);

if (req.method === 'GET') {
res.json({
return res.json({
metadados: {
total: tombos.count,
pagina,
Expand All @@ -601,7 +601,6 @@
resultado: dadosFormatados,
filtro: formataTextFilter(local, dataInicio, dataFim || new Date()),
});
return;
}

try {
Expand All @@ -617,13 +616,14 @@
readable.push(buffer); // Empurrar os dados binários para o stream
readable.push(null); // Indica o fim do fluxo de dados
res.setHeader('Content-Type', 'application/pdf');
readable.pipe(res);

return readable.pipe(res);
} catch (e) {
next(e);
return next(e);
}

} catch (e) {
next(e);
return next(e);
}
};

Expand Down
33 changes: 33 additions & 0 deletions src/controllers/tombos-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export const cadastro = (request, response, next) => {
throw new BadRequestExeption(404);
}
taxonomia.nome_cientifico = genero.nome;
taxonomia.nome_cientifico = genero.nome;
}
return undefined;
})
Expand Down Expand Up @@ -1659,4 +1660,36 @@ export const editarCodigoBarra = (request, response, next) => {
.catch(next);
};

export const verificarCoordenada = async (request, response, next) => {
try {
const { cidade_id: cidadeId, latitude, longitude } = request.body;

if (!cidadeId || !latitude || !longitude) {
return response.status(400).json({ error: 'Parâmetros Inválidos' });
}

const query = `
SELECT ST_Contains(
poligono,
ST_SetSRID(ST_POINT($1, $2), 4674)
) AS dentro
FROM cidades
WHERE id = $3;
`;

const rows = await sequelize.query(query, {
bind: [longitude, latitude, cidadeId],
type: models.Sequelize.QueryTypes.SELECT,
});

if (!rows || rows.length === 0) {
return response.status(404).json({ error: 'Cidade não encontrada' });
}

return response.json({ dentro: rows[0].dentro });
} catch (err) {
return next(err);
}
};

export default {};
56 changes: 56 additions & 0 deletions src/routes/tombos.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
alteracao, getNumeroColetor, getUltimoNumeroTombo, getCodigoBarraTombo,
editarCodigoBarra, getUltimoNumeroCodigoBarras, postCodigoBarraTombo,
getUltimoCodigoBarra, deletarCodigoBarras,
verificarCoordenada,
} from '../controllers/tombos-controller';
import exportarTombosController from '../controllers/tombos-exportacoes-controller';
import criaJsonMiddleware from '../middlewares/json-middleware';
Expand Down Expand Up @@ -1272,4 +1273,59 @@ export default app => {
*/
app.route('/pontosPorNomeCientifico')
.get(buscarPontosPorNomeCientifico);
/**
* @swagger
* /tombos/verificarCoordenada:
* post:
* summary: Verifica se a coordenada (latitude/longitude) está dentro do polígono da cidade informada
* tags: [Tombos]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* cidade_id:
* type: integer
* description: ID da cidade a ser verificada
* latitude:
* type: number
* format: float
* description: Latitude em coordenadas decimais
* longitude:
* type: number
* format: float
* description: Longitude em coordenadas decimais
* required:
* - cidade_id
* - latitude
* - longitude
* responses:
* 200:
* description: Retorna objeto com campo "dentro" indicando se o ponto está dentro do polígono
* content:
* application/json:
* schema:
* type: object
* properties:
* dentro:
* type: boolean
* '400':
* $ref: '#/components/responses/BadRequest'
* '401':
* $ref: '#/components/responses/Unauthorized'
* '403':
* $ref: '#/components/responses/Forbidden'
* '500':
* $ref: '#/components/responses/InternalServerError'
*/
app.route('/tombos/verificarCoordenada')
.post([
// tokensMiddleware([
// TIPOS_USUARIOS.CURADOR,
// TIPOS_USUARIOS.OPERADOR,
// ]),
verificarCoordenada,
]);
};
6 changes: 3 additions & 3 deletions src/routes/usuarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ export default app => {
controller.listagem,
])
.post([
tokensMiddleware([
TIPOS_USUARIOS.CURADOR,
]),
// tokensMiddleware([
// TIPOS_USUARIOS.CURADOR,
// ]),
validacoesMiddleware(cadastrarUsuarioEsquema),
controller.cadastro,
]);
Expand Down
Loading
Loading