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
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"@babel/plugin-proposal-class-properties"
],
"comments": false,
"comments": true,
"sourceMaps": "inline",
"ignore": [
"**/*.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import routes from './routes';
const app = express();
app.use(cors());

app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.use(parser.json());
app.use(morgan('dev'));

Expand Down
1 change: 1 addition & 0 deletions src/config/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const options = {
},
apis: [
'./src/routes/*.js',
'./dist/routes/*.js',
],
};

Expand Down
2 changes: 2 additions & 0 deletions src/controllers/fichas-tombos-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function formataDataSaida(data) {

export default function fichaTomboController(request, response, next) {
const { tombo_id: tomboId } = request.params;
const { qtd } = request.query;

Promise.resolve()
.then(() => {
Expand Down Expand Up @@ -250,6 +251,7 @@ export default function fichaTomboController(request, response, next) {
romano_data_tombo: romanoDataTombo,
romano_data_identificacao: romanoDataIdentificacao,
romano_data_coleta: romanoDataColeta,
numero_copias: qtd || 1,
};

const caminhoArquivoHtml = path.resolve(__dirname, '../views/ficha-tombo.ejs');
Expand Down
815 changes: 182 additions & 633 deletions src/controllers/pendencias-controller.js

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions src/controllers/taxonomias-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,8 @@ export const cadastrarSubfamilia = (request, response, next) => {

return familiaEncontrada;
})
.then(familia => Subfamilia.create({ nome,
.then(() => Subfamilia.create({ nome,
familia_id: familiaId,
reino_id: familia.reino_id,
}, transaction));
sequelize.transaction(callback)
.then(subfamiliaCriado => {
Expand Down Expand Up @@ -476,9 +475,8 @@ export const cadastrarGenero = (request, response, next) => {

return familiaEncontrada;
})
.then(familia => Genero.create({ nome,
.then(() => Genero.create({ nome,
familia_id: familiaId,
reino_id: familia.reino_id,
}, transaction));
sequelize.transaction(callback)
.then(generoCriado => {
Expand Down Expand Up @@ -676,7 +674,6 @@ export const cadastrarEspecie = (request, response, next) => {
nome,
genero_id: generoId,
familia_id: genero.familia_id,
reino_id: genero.reino_id,
autor_id: autorId,
},
transaction
Expand Down Expand Up @@ -905,7 +902,6 @@ export const cadastrarSubespecie = (request, response, next) => {
genero_id: especie.genero_id,
especie_id: especieId,
familia_id: especie.familia_id,
reino_id: especie.reino_id,
autor_id: autorId,
}, transaction));
sequelize.transaction(callback)
Expand Down Expand Up @@ -1143,7 +1139,6 @@ export const cadastrarVariedade = (request, response, next) => {
genero_id: especie.genero_id,
especie_id: especieId,
familia_id: especie.familia_id,
reino_id: especie.reino_id,
autor_id: autorId,
},
transaction
Expand Down
88 changes: 10 additions & 78 deletions src/controllers/tombos-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ export const cadastro = (request, response, next) => {
observacoes,
} = request.body.json;
let tomboCriado = null;
let nomeFamilia = '';
let nomeGenero = '';
let nomeSubfamilia = '';
let nomeEspecie = '';
let nomeSubespecie = '';
let nomeVariedade = '';

const callback = transaction =>
Promise.resolve()
Expand Down Expand Up @@ -162,7 +156,6 @@ export const cadastro = (request, response, next) => {
throw new BadRequestExeption(402);
}
taxonomia.nome_cientifico = familia.nome;
nomeFamilia = familia.nome;
}
return undefined;
})
Expand All @@ -184,7 +177,6 @@ export const cadastro = (request, response, next) => {
throw new BadRequestExeption(403);
}
taxonomia.nome_cientifico += ` ${subfamilia.nome}`;
nomeSubfamilia = subfamilia.nome;
}
return undefined;
})
Expand All @@ -206,7 +198,6 @@ export const cadastro = (request, response, next) => {
throw new BadRequestExeption(404);
}
taxonomia.nome_cientifico += ` ${genero.nome}`;
nomeGenero = genero.nome;
}
return undefined;
})
Expand All @@ -228,7 +219,6 @@ export const cadastro = (request, response, next) => {
throw new BadRequestExeption(405);
}
taxonomia.nome_cientifico += ` ${especie.nome}`;
nomeEspecie = especie.nome;
}
return undefined;
})
Expand All @@ -250,7 +240,6 @@ export const cadastro = (request, response, next) => {
throw new BadRequestExeption(406);
}
taxonomia.nome_cientifico += ` ${subespecie.nome}`;
nomeSubespecie = subespecie.nome;
}
return undefined;
})
Expand All @@ -272,7 +261,6 @@ export const cadastro = (request, response, next) => {
throw new BadRequestExeption(407);
}
taxonomia.nome_cientifico += ` ${variedade.nome}`;
nomeVariedade = variedade.nome;
}
return undefined;
})
Expand Down Expand Up @@ -321,7 +309,7 @@ export const cadastro = (request, response, next) => {
jsonTombo = {
...jsonTombo,
// eslint-disable-next-line max-len
...pick(taxonomia, ['nome_cientifico', 'variedade_id', 'especie_id', 'genero_id', 'familia_id', 'reino_id', 'sub_familia_id', 'sub_especie_id']),
...pick(taxonomia, ['nome_cientifico', 'variedade_id', 'especie_id', 'genero_id', 'familia_id', 'sub_familia_id', 'sub_especie_id']),
};
}
if (colecoesAnexas && colecoesAnexas.id) {
Expand Down Expand Up @@ -384,68 +372,19 @@ export const cadastro = (request, response, next) => {
}
if (tomboCriado !== null) {
if (identificacao && identificacao.identificadores && identificacao.identificadores.length > 0) {
const promises = [];
identificacao.identificadores.forEach((identificador_id, index) => {
const promises = identificacao.identificadores.map((identificador_id, index) => {
const isPrincipal = index === 0;
const dadosIdentificadores = {
identificador_id,
tombo_hcf: tomboCriado.hcf,
ordem: index + 1,
principal: isPrincipal,
};
promises.push(
TomboIdentificador.create(dadosIdentificadores, {
transaction,
})
);
return TomboIdentificador.create(dadosIdentificadores, {
transaction,
});
});
let status = 'ESPERANDO';
const jsonTaxonomia = {};
const dados = {
tombo_hcf: tomboCriado.hcf,
usuario_id: identificacao.identificadores[0],
status,
ativo: true,
identificacao: 1,
};

principal.hcf = tomboCriado.hcf;
if (request.usuario.tipo_usuario_id === 1) {
status = 'APROVADO';
}
dados.status = status;
if (nomeFamilia !== '') {
jsonTaxonomia.familia_nome = nomeFamilia;
}
if (nomeSubfamilia !== '') {
jsonTaxonomia.subfamilia_nome = nomeSubfamilia;
}
if (nomeGenero !== '') {
jsonTaxonomia.genero_nome = nomeGenero;
}
if (nomeEspecie !== '') {
jsonTaxonomia.especie_nome = nomeEspecie;
}
if (nomeSubespecie !== '') {
jsonTaxonomia.subespecie_nome = nomeSubespecie;
}
if (nomeVariedade !== '') {
jsonTaxonomia.variedade_nome = nomeVariedade;
}
dados.tombo_json = JSON.stringify(jsonTaxonomia);

if (identificacao && identificacao.data_identificacao) {
if (identificacao.data_identificacao.dia) {
dados.data_identificacao_dia = identificacao.data_identificacao.dia;
}
if (identificacao.data_identificacao.mes) {
dados.data_identificacao_mes = identificacao.data_identificacao.mes;
}
if (identificacao.data_identificacao.ano) {
dados.data_identificacao_ano = identificacao.data_identificacao.ano;
}
}
return Alteracao.create(dados, { transaction });
return Promise.all(promises);
}
}
return undefined;
Expand Down Expand Up @@ -538,7 +477,7 @@ function alteracaoCuradorouOperador(request, response, next) {
const dataIdentificacao = body?.identificacao?.data_identificacao;

const { coletores } = body || null;
const { complementares } = body?.coletor_complementar?.complementares || null;
const complementares = body?.coletor_complementar?.complementares || null;
const colecoesAnexasTipo = body?.colecoes_anexas?.tipo;
const colecoesAnexasObservacoes = body?.colecoes_anexas?.observacoes;

Expand Down Expand Up @@ -689,13 +628,6 @@ function alteracaoCuradorouOperador(request, response, next) {
.catch(next);
}
});
// .then(alteracaoIdent => {
// if (request.usuario.tipo_usuario_id === 3) {
// if (!alteracaoIdent) {
// throw new BadRequestExeption(421);
// }
// }
// });
}

export function alteracao(request, response, next) {
Expand All @@ -709,10 +641,11 @@ export function alteracao(request, response, next) {
};
sequelize.transaction(callback)
.then(() => {
response.status(codigos.LISTAGEM).send();
if (request.usuario.tipo_usuario_id === 3) {
response.status(codigos.EDITAR_SEM_RETORNO).send();
}
})
.catch(next);

}

export const desativar = (request, response, next) => {
Expand Down Expand Up @@ -1399,7 +1332,6 @@ export const obterTombo = async (request, response, next) => {
Familia.findAll({
where: {
id: dadosTombo.familia?.id,
reino_id: dadosTombo.reino?.id,
},
})
)
Expand Down
9 changes: 0 additions & 9 deletions src/models/Especie.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ function associate(modelos) {
Familia,
Especie,
Genero,
Reino,
} = modelos;

Especie.belongsTo(Autor, {
Expand All @@ -20,10 +19,6 @@ function associate(modelos) {
foreignKey: 'familia_id',
});

Especie.belongsTo(Reino, {
foreignKey: 'reino_id',
});

}

export const defaultScope = {
Expand Down Expand Up @@ -63,10 +58,6 @@ export default (Sequelize, DataTypes) => {
type: DataTypes.INTEGER,
allowNull: true,
},
reino_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
};

const options = {
Expand Down
9 changes: 0 additions & 9 deletions src/models/Genero.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ function associate(modelos) {
const {
Familia,
Genero,
Reino,
} = modelos;

Genero.belongsTo(Familia, {
foreignKey: 'familia_id',
});

Genero.belongsTo(Reino, {
foreignKey: 'reino_id',
});
}

export const defaultScope = {
Expand Down Expand Up @@ -43,10 +38,6 @@ export default (Sequelize, DataTypes) => {
type: DataTypes.INTEGER,
allowNull: false,
},
reino_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
};

const options = {
Expand Down
8 changes: 0 additions & 8 deletions src/models/Subespecie.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ function associate(modelos) {
Especie,
Genero,
Subespecie,
Reino,
} = modelos;

Subespecie.belongsTo(Autor, {
Expand All @@ -22,9 +21,6 @@ function associate(modelos) {
foreignKey: 'especie_id',
as: 'especie',
});
Subespecie.belongsTo(Reino, {
foreignKey: 'reino_id',
});
}

export const defaultScope = {
Expand Down Expand Up @@ -68,10 +64,6 @@ export default (Sequelize, DataTypes) => {
type: DataTypes.INTEGER,
allowNull: true,
},
reino_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
};

const options = {
Expand Down
9 changes: 0 additions & 9 deletions src/models/Subfamilia.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ function associate(modelos) {
Autor,
Familia,
Subfamilia,
Reino,
} = modelos;

Subfamilia.belongsTo(Autor, {
Expand All @@ -14,10 +13,6 @@ function associate(modelos) {
Subfamilia.belongsTo(Familia, {
foreignKey: 'familia_id',
});

Subfamilia.belongsTo(Reino, {
foreignKey: 'reino_id',
});
}

export const defaultScope = {
Expand Down Expand Up @@ -49,10 +44,6 @@ export default (Sequelize, DataTypes) => {
type: DataTypes.INTEGER,
allowNull: false,
},
reino_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
};

const options = {
Expand Down
Loading