Skip to content
Snippets Groups Projects
Commit 85138667 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Merge branch 'feature_infraestrutura' into development

Closes: !85
parents d3dffc36 e175e45a
No related branches found
No related tags found
1 merge request!116Release v1.0.0
Pipeline #
......@@ -40,4 +40,10 @@ function execSqlQuery(sqlQuery, sqlQueryParams = []) {
});
}
module.exports = execSqlQuery;
function execMultiQuery(querySet = []) {
// Issue all queries concurrently to the database, for every query object in the iterable
// NOTE: Array.map() returns a copy of the original array with each object 'mapped'.
return querySet.map((qry) => { return execSqlQuery(qry.toString()); });
}
module.exports = {execSqlQuery, execMultiQuery};
......@@ -29,6 +29,7 @@ const ids = {
adm_dependency_detailed_id: admDependencyPriv,
location_id: location,
rural_location_id: ruralLocation,
location_detailed_id: ruralLocation,
ethnic_group_id: ethnicGroup,
agreement_id: agreement,
integral_time_id: booleanVariable,
......
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const db = require(`${libs}/db/query_exec`);
// Middleware that executes multiples queries
function multiQuery(req, res, next) {
Promise.all(db.execMultiQuery(req.querySet)).then((queryResults) => {
req.result = queryResults;
next();
}).catch((err) => {
log.error(`[SQL query error] ${err}`);
next(err);
});
}
module.exports = multiQuery;
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const execQuery = require(`${libs}/db/query_exec`);
const db = require(`${libs}/db/query_exec`);
// Middleware that executes a query defined by a squel object in req.sql
function query(req, res, next) {
let sql = req.sql.toParam();
log.info(`Executando query ${req.sql.toString()}`);
execQuery(sql.text, sql.values).then((result) => {
req.result = result;
next();
execute(sql.text, sql.values, (err, result) => {
if(err) {
log.error(err.stack);
next(new Error('Request could not be satisfied due to a database error.'));
} else {
req.result = result;
next();
}
});
}
function execute(text, values, cb) {
db.execSqlQuery(text, values).then((result) => {
cb(null, result);
}, (error) => {
log.error(error.stack);
next(new Error('Request could not be satisfied due to a database error.'));
cb(new Error('Request could not be satisfied due to a database error.'));
});
}
......
......@@ -48,6 +48,8 @@ const resetToken = require(`${libs}/routes/resetToken`);
const educationYears = require(`${libs}/routes/educationYears`);
const infrastructure = require(`${libs}/routes/infrastructure`);
api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API is running' });
});
......@@ -74,5 +76,6 @@ api.use('/auth/token', oauth2.token);
api.use('/verify', verifyToken);
api.use('/reset', resetToken);
api.use('/education_years', educationYears);
api.use('/infrastructure', infrastructure);
module.exports = api;
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment