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
20 changes: 20 additions & 0 deletions src/controllers/splinker-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
Especie,
Tombo,
TomboFoto,
SplinkerExecucao,
} = models;

function obtemNomeArquivoTxt() {
Expand Down Expand Up @@ -259,4 +260,23 @@ export const obterModeloSPLinker = async (request, response, next) => {
response.end();
};

export const obterUltimaExecucaoSPLinker = async (request, response, next) => {
try {
const execucao = await SplinkerExecucao.findOne({
order: [['data_hora', 'DESC']],
attributes: [
// data_hora é "timestamp without time zone" já em horário de Brasília;
// to_char evita que o driver reinterprete o valor literal como UTC.
[models.sequelize.fn('to_char', models.sequelize.col('data_hora'), 'YYYY-MM-DD"T"HH24:MI:SS'), 'data_hora'],
'ultimo_tombo_hcf',
'sucesso',
],
});

response.json(execucao);
} catch (error) {
next(error);
}
};

export default {};
37 changes: 37 additions & 0 deletions src/models/SplinkerExecucao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function associate(/* models */) {
// não há associações para este model
}

export default (Sequelize, DataTypes) => {

const attributes = {
data_hora: {
type: DataTypes.DATE,
allowNull: true,
},
ultimo_tombo_hcf: {
type: DataTypes.INTEGER,
allowNull: true,
},
sucesso: {
type: DataTypes.BOOLEAN,
allowNull: true,
},
log_saida: {
type: DataTypes.TEXT,
allowNull: true,
},
};

const options = {
freezeTableName: false,
timestamps: false,
tableName: 'splinker_execucoes',
};

const Model = Sequelize.define('splinker_execucoes', attributes, options);

Model.associate = associate;

return Model;
};
12 changes: 11 additions & 1 deletion src/routes/splinker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { obterModeloSPLinker } from '../controllers/splinker-controller';
import { obterModeloSPLinker, obterUltimaExecucaoSPLinker } from '../controllers/splinker-controller';
import tokensMiddleware, { TIPOS_USUARIOS } from '../middlewares/tokens-middleware';

export default app => {
Expand All @@ -11,4 +11,14 @@ export default app => {
]),
obterModeloSPLinker,
]);

app.route('/splinker/ultima-execucao')
.get([
tokensMiddleware([
TIPOS_USUARIOS.CURADOR,
TIPOS_USUARIOS.OPERADOR,
TIPOS_USUARIOS.IDENTIFICADOR,
]),
obterUltimaExecucaoSPLinker,
]);
};
Loading