Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules/

uploads/
mysql/data/
postgresql/
reports/data/fs.journal
reports/data/fs.version
reports/data/profiles
Expand Down
24 changes: 23 additions & 1 deletion src/controllers/tombos-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import models from '../models';
import codigos from '../resources/codigos-http';
import verifyRecaptcha from '../utils/verify-recaptcha';
import { aprovarPendencia } from './pendencias-controller';

const {
Solo, Relevo, Cidade, Estado, Vegetacao, FaseSucessional, Pais, Tipo, LocalColeta, Familia, sequelize,
Genero, Subfamilia, Autor, Coletor, Variedade, Subespecie, TomboFoto, Identificador,
Expand All @@ -35,6 +34,28 @@ function parseDataTombo(valor) {
return null;
}

const getProximoNumeroTombo = async () => {
const resultado = await Tombo.findOne({
attributes: [
[fn('MAX', col('hcf')), 'max_hcf'],
],
raw: true,
});
const maxNumero = resultado?.max_hcf;
return maxNumero ? Number(maxNumero) + 1 : 1;
};

export const getProximoNumeroTomboEndPoint = async (request, response, next) => {
try {
const proximoNumero = await getProximoNumeroTombo();
response
.status(codigos.BUSCAR_UM_ITEM)
.json({ hcf: proximoNumero });
} catch (error) {
next(error);
}
};

export const cadastro = (request, response, next) => {
const {
principal,
Expand Down Expand Up @@ -299,6 +320,7 @@ export const cadastro = (request, response, next) => {
// /////////// CADASTRA TOMBO /////////////
.then(() => {
let jsonTombo = {
hcf: principal.hcf,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JosueModesto o André me confirmou que o compartamento antigo estava correto, então por favor, remove esta linha aqui que pega o número que o frontend enviou, mantém só o código que você fez pra gerar o próximo número mesmo.

Image

numero_coleta: principal.numero_coleta,
cidade_id: localidade.cidade_id,
coletor_id: coletor,
Expand Down
13 changes: 12 additions & 1 deletion src/routes/tombos.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
alteracao, getNumeroColetor, getUltimoNumeroTombo, getCodigoBarraTombo,
editarCodigoBarra, getUltimoNumeroCodigoBarras, postCodigoBarraTombo,
verificarCoordenada, getUltimoCodigoBarra, deletarCodigoBarras, listagemTombosPorIdentificador,
relatorioPorPeriodo,
relatorioPorPeriodo, getProximoNumeroTomboEndPoint,
} from '../controllers/tombos-controller';
import exportarTombosController from '../controllers/tombos-exportacoes-controller';
import criaJsonMiddleware from '../middlewares/json-middleware';
Expand All @@ -21,6 +21,7 @@ import coletorCadastro from '../validators/coletor-cadastro';
import cadastrarTipoEsquema from '../validators/tipo-cadastro';
import cadastrarTomboEsquema from '../validators/tombo-cadastro';
import listagemTombo from '../validators/tombo-listagem';

/**
* @swagger
* tags:
Expand Down Expand Up @@ -355,6 +356,16 @@ export default app => {
getUltimoNumeroTombo,
]);

app.route('/tombos/proximo_numero')
.get([
tokensMiddleware([
TIPOS_USUARIOS.CURADOR,
TIPOS_USUARIOS.OPERADOR,
TIPOS_USUARIOS.IDENTIFICADOR,
]),
getProximoNumeroTomboEndPoint,
]);

/**
* @swagger
* /tombos/ultimo_codigo_barra:
Expand Down
4 changes: 4 additions & 0 deletions src/validators/tombo-cadastro.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default {
},
isInt: true,
},
'json.principal.hcf': {
in: 'body',
isInt: true,
},
'json.principal.data_tombo': {
in: 'body',
custom: {
Expand Down
Loading