Skip to content
Snippets Groups Projects
Commit c9feaabd authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Year Range in idhm

parent f3b91149
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!60IDHMR and IDHM routes
Pipeline #
......@@ -23,6 +23,22 @@ idhmApp.get('/year_range', (req, res, next) => {
.field('MIN(adh_idh.ano_censo)', 'start_year')
.field('MAX(adh_idh.ano_censo)', 'end_year');
next();
}, query, (req, res, next) => {
req.sql.from('adh_idh_uf')
.field('MIN(adh_idh_uf.ano_censo)', 'start_year')
.field('MAX(adh_idh_uf.ano_censo)', 'end_year');
req.old_result = req.result;
next();
}, query, (req, res, next) => {
// console.log(req.old_result[0].start_year);
// console.log(req.result[0].start_year);
if (req.old_result[0].start_year < req.result[0].start_year) {
req.result[0].start_year = req.old_result[0].start_year;
}
if (req.old_result[0].end_year > req.result[0].end_year) {
req.result[0].end_year = req.old_result[0].old_result;
}
next();
}, query, response('range'));
idhmApp.get('/IDHM_level', (req, res, next) => {
......@@ -37,7 +53,6 @@ idhmApp.get('/IDHM_level', (req, res, next) => {
next();
}, response('IDHM_level'));
rqf.addField({
name: 'filter',
field: false,
......@@ -78,30 +93,32 @@ rqf.addField({
foreign: 'estado_id',
foreignTable: 'adh_idh_uf'
}
}).addValue({
name: 'min_year',
table: 'adh_idh',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'adh_idh',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'min_year',
table: '@',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
table: '@',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: '@',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
table: '@',
field: 'ano_censo'
}
});
idhmApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
idhmApp.get('/', rqf.parse(), (req, res, next) => {
log.debug(req.sql.toParam());
if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0 ) {
res.status(400);
......@@ -111,20 +128,17 @@ idhmApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
});
}
if ("state" in req.filter) {
req.sql.field('(adh_idh_uf.idhm)', 'IDHM')
.field("'Brasil'", 'name')
.field('adh_idh_uf.estado_id', 'estado_id')
.field('adh_idh_uf.ano_censo', 'year')
.from('adh_idh_uf')
req.sql.from('adh_idh_uf')
.field('adh_idh_uf.idhm', 'IDHM')
.field('adh_idh_uf.ano_censo', 'year')
.field('adh_idh_uf.estado_id', 'state_id');
} else if ("city" in req.filter) {
req.sql.field('(adh_idh.idhm)', 'IDHM')
.field("'Brasil'", 'name')
.field('adh_idh.municipio_id', 'municipio_id')
.field('adh_idh.estado_id', 'estado_id')
.field('adh_idh.ano_censo', 'year')
.from('adh_idh')
}
next();
}, query, id2str.transform(true), response('idhm'));
req.sql.from('adh_idh')
.field('adh_idh.idhm', 'IDHM')
.field('adh_idh.ano_censo', 'year')
.field('adh_idh.municipio_id', 'city_id');
}
next();
}, rqf.build(),query, response('idhm'));
module.exports = idhmApp;
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