Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/controllers/pendencias-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,10 @@
updateTombo.cor = alteracao.cor ? alteracao.cor.toUpperCase() : null;
}

if(alteracao.data_tombo !== undefined){
updateTombo.data_tombo = alteracao.data_tombo;
}

if (alteracao.data_coleta_dia !== undefined) {
updateTombo.data_coleta_dia = alteracao.data_coleta_dia;
}
Expand Down Expand Up @@ -1374,7 +1378,7 @@

if (nomesCientificosPartes.length > 0) {
updateTombo.nome_cientifico = nomesCientificosPartes.join(' ');
} else if (Object.keys(updateTombo).some(key => key.includes('familia_id') || key.includes('genero_id') || key.includes('especie_id') || key.includes('sub_especie_id') || key.includes('variedade_id'))) {

Check warning on line 1381 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 207. Maximum allowed is 150
updateTombo.nome_cientifico = null;
}

Expand Down Expand Up @@ -1759,21 +1763,21 @@
if (objetoAlterado.genero_nome) parametros.genero = objetoAlterado.genero_nome;
if (objetoAlterado.especie_nome) parametros.especie = objetoAlterado.especie_nome;

if (objetoAlterado.familia_id) parametros.familia = await Familia.findOne({ where: { id: objetoAlterado.familia_id }, raw: true, nest: true });

Check warning on line 1766 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 151. Maximum allowed is 150
if (objetoAlterado.subfamilia_id) parametros.subfamilia = await Subfamilia.findOne({ where: { id: objetoAlterado.subfamilia_id }, raw: true, nest: true });

Check warning on line 1767 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 163. Maximum allowed is 150
if (objetoAlterado.genero_id) parametros.genero = await Genero.findOne({ where: { id: objetoAlterado.genero_id }, raw: true, nest: true });
if (objetoAlterado.especie_id) parametros.especie = await Especie.findOne({ where: { id: objetoAlterado.especie_id }, raw: true, nest: true });

Check warning on line 1769 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 151. Maximum allowed is 150

if (objetoAlterado.identificadores) parametros.identificador = await Usuario.findOne({ where: { id: objetoAlterado.identificadores }, raw: true, nest: true });

Check warning on line 1771 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 167. Maximum allowed is 150
if (objetoAlterado.fase_sucessional_id) parametros.faseSucessional = await FaseSucessional.findOne({ where: { numero: objetoAlterado.fase_sucessional_id }, raw: true, nest: true });

Check warning on line 1772 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 189. Maximum allowed is 150
if (objetoAlterado.vegetacao_id) parametros.vegetacao = await Vegetacao.findOne({ where: { id: objetoAlterado.vegetacao_id }, raw: true, nest: true });

Check warning on line 1773 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 159. Maximum allowed is 150
if (objetoAlterado.relevo_id) parametros.relevo = await Relevo.findOne({ where: { id: objetoAlterado.relevo_id }, raw: true, nest: true });
if (objetoAlterado.solo_id) parametros.solo = await Solo.findOne({ where: { id: objetoAlterado.solo_id }, raw: true, nest: true });
if (objetoAlterado.cidade_id) parametros.cidade = await Cidade.findOne({ where: { id: objetoAlterado.cidade_id }, raw: true, nest: true });
if (objetoAlterado.tipo_id) parametros.tipo = await Tipo.findOne({ where: { id: objetoAlterado.tipo_id }, raw: true, nest: true });
if (objetoAlterado.entidade_id) parametros.entidade = await Herbario.findOne({ where: { id: objetoAlterado.entidade_id }, raw: true, nest: true });

Check warning on line 1778 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 155. Maximum allowed is 150
if (objetoAlterado.variedade_id) parametros.variedade = await Variedade.findOne({ where: { id: objetoAlterado.variedade_id }, raw: true, nest: true });

Check warning on line 1779 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 159. Maximum allowed is 150
if (objetoAlterado.sub_especie_id) parametros.subespecie = await Subespecie.findOne({ where: { id: objetoAlterado.sub_especie_id }, raw: true, nest: true });

Check warning on line 1780 in src/controllers/pendencias-controller.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 165. Maximum allowed is 150

const tombo = await Tombo.findOne({
where: { hcf: alteracao.dataValues.tombo_hcf, ativo: true },
Expand Down
21 changes: 20 additions & 1 deletion src/controllers/tombos-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ const {
ColecaoAnexa, Especie, Herbario, Tombo, Alteracao, TomboIdentificador, ColetorComplementar, Sequelize: { Op },
} = models;

function parseDataTombo(valor) {
const partes = valor.split(/[-]/).map(p => p.trim());
if (partes.length >= 3) {
const [anoStr, mesStr, diaStr] = partes;
const dia = parseInt(diaStr, 10);
const mes = parseInt(mesStr, 10) - 1;
const ano = parseInt(anoStr, 10);
if (!Number.isNaN(dia) && !Number.isNaN(mes) && !Number.isNaN(ano)) {
return new Date(ano, mes, dia, 12, 0, 0, 0);
}
return null;
}
return null;
}

export const cadastro = (request, response, next) => {
const {
principal,
Expand Down Expand Up @@ -277,7 +292,8 @@ export const cadastro = (request, response, next) => {
local_coleta_id: localidade.local_coleta_id,
cor: principal.cor,
coletor_id: coletor,
};
data_tombo: parseDataTombo(principal.data_tombo),
Comment thread
MatCoitinho marked this conversation as resolved.
};

if (paisagem?.descricao) {
jsonTombo.descricao = paisagem.descricao;
Expand Down Expand Up @@ -478,6 +494,9 @@ function alteracaoCuradorouOperador(request, response, transaction) {
const { cor } = body.principal || {};
if (cor !== undefined) update.cor = cor;

const dataTombo = body?.principal?.data_tombo;
if(dataTombo !== undefined) update.data_tombo = parseDataTombo(dataTombo);

const familiaId = body?.taxonomia?.familia_id;
if (familiaId !== undefined) update.familia_id = familiaId;

Expand Down
7 changes: 7 additions & 0 deletions src/validators/tombo-alteracao.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import validaColecoesAnexas from './tombo-colecoes-anexas';
import validaCor from './tombo-cor';
import validaData from './tombo-data';
import validaDataTombo from './tombo-data-tombo';

const validaColetores = coletores => {
if (!Array.isArray(coletores) || coletores.length < 1) {
Expand Down Expand Up @@ -34,6 +35,12 @@ export default {
},
isInt: true,
},
'json.principal.data_tombo': {
Comment thread
ncs92 marked this conversation as resolved.
in: 'body',
custom: {
options: validaDataTombo,
},
},
'json.principal.data_coleta': {
in: 'body',
custom: {
Expand Down
24 changes: 7 additions & 17 deletions src/validators/tombo-cadastro.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import validaColecoesAnexas from './tombo-colecoes-anexas';
import validaCor from './tombo-cor';
import validaData from './tombo-data';

// const validaColetores = coletores => {
// if (!Array.isArray(coletores)) {
// return false;
// }

// if (coletores.length <= 0) {
// return false;
// }

// for (let i = 0; i < coletores.length; i += 1) {
// if (!Number.isInteger(coletores[i])) {
// return false;
// }
// }
// return true;
// };
import validaDataTombo from './tombo-data-tombo';

export default {
'json.principal.nome_popular': {
Expand All @@ -40,6 +24,12 @@ export default {
},
isInt: true,
},
'json.principal.data_tombo': {
Comment thread
MatCoitinho marked this conversation as resolved.
in: 'body',
custom: {
options: validaDataTombo,
},
},
'json.principal.data_coleta': {
in: 'body',
custom: {
Expand Down
20 changes: 20 additions & 0 deletions src/validators/tombo-data-tombo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default (data) => {
if (typeof data !== 'string') {
return false;
}

const isoRegex = /^\d{4}-\d{2}-\d{2}$/;
if (!isoRegex.test(data)) {
return false;
}

const [, mesStr, diaStr] = data.split('-');
const mes = Number(mesStr);
const dia = Number(diaStr);

if (mes < 1 || mes > 12) return false;
if (dia < 1 || dia > 31) return false;


return true;
}