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

IDHR route

parent 456ee9ae
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!58Pib per capita e População
Pipeline #
...@@ -30,6 +30,8 @@ const classroom = require('./classroom'); ...@@ -30,6 +30,8 @@ const classroom = require('./classroom');
const teacher = require('./teacher'); const teacher = require('./teacher');
const idhmr = require('./idhmr');
api.get('/', (req, res) => { api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API is running' }); res.json({ msg: 'SimCAQ API is running' });
}); });
...@@ -46,5 +48,6 @@ api.use('/school', cache('15 day'), school); ...@@ -46,5 +48,6 @@ api.use('/school', cache('15 day'), school);
api.use('/spatial', cache('1 day'), spatial); api.use('/spatial', cache('1 day'), spatial);
api.use('/classroom', cache('15 day'), classroom); api.use('/classroom', cache('15 day'), classroom);
api.use('/teacher', cache('1 day'), teacher); api.use('/teacher', cache('1 day'), teacher);
api.use('/idhmr', cache('1 day'), idhmr);
module.exports = api; module.exports = api;
const express = require('express');
const idhmrApp = express.Router();
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const squel = require('squel');
const query = require(`${libs}/middlewares/query`);
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const id2str = require(`${libs}/middlewares/id2str`);
let rqf = new ReqQueryFields();
idhmrApp.get('/year_range', (req, res, next) => {
req.sql.from('adh_idh')
.field('MIN(adh_idh.ano_censo)', 'start_year')
.field('MAX(adh_idh.ano_censo)', 'end_year');
next();
}, query, response('range'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'municipio_id',
table: 'adh_idh'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'adh_idh'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
where: {
relation: '=',
type: 'integer',
field: 'estado_id',
table: 'adh_idh'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'adh_idh'
}
}).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'
}
});
idhmrApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
log.debug(req.sql.toParam());
req.sql.field('(adh_idh.idhm_r)', 'IDHMR')
.field("'Brasil'", 'name')
.field('adh_idh.municipio_id', 'municipio_id')
.field('adh_idh.ano_censo', 'year')
.from('adh_idh')
next();
}, query, id2str.transform(true), response('idhmr'));
module.exports = idhmrApp;
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