Skip to content
Snippets Groups Projects
Commit 45d93c15 authored by Lucas Gabriel Lima's avatar Lucas Gabriel Lima
Browse files

create route for city pibpercapita

parent 79cae217
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!58Pib per capita e População
Pipeline #
......@@ -32,6 +32,8 @@ const teacher = require('./teacher');
const idhmr = require('./idhmr');
const pibpercapita = require('./pibpercapita')
api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API is running' });
});
......@@ -49,5 +51,6 @@ api.use('/spatial', cache('1 day'), spatial);
api.use('/classroom', cache('15 day'), classroom);
api.use('/teacher', cache('1 day'), teacher);
api.use('/idhmr', cache('1 day'), idhmr);
api.use('/pibpercapita', cache('1 day'), pibpercapita);
module.exports = api;
......@@ -18,7 +18,7 @@ const id2str = require(`${libs}/middlewares/id2str`);
let rqf = new ReqQueryFields();
idhmrApp.get('/year_range', (req, res, next) => {
pibpercapitaApp.get('/year_range', (req, res, next) => {
req.sql.from('ibge_pib')
.field('MIN(ibge_pib.ano_censo)', 'start_year')
.field('MAX(ibge_pib.ano_censo)', 'end_year');
......@@ -33,7 +33,51 @@ rqf.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: 'ibge_pib'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'ibge_pib'
}
}).addValue({
name: 'min_year',
table: 'ibge_pib',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'ibge_pib',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
});
pibpercapitaApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
log.debug(req.sql.toParam());
req.sql.field('(ibge_pib.pib_per_capita)', 'pibpercapita')
.field('ibge_pib.municipio_id', 'municipio_id')
.field('ibge_pib.ano_censo', 'year')
.from('ibge_pib')
next();
}, query, id2str.transform(true), response('pibpercapita'));
module.exports = pibpercapitaApp;
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