Skip to content
Snippets Groups Projects
Commit 6325779c authored by Gabriel Ruschel's avatar Gabriel Ruschel
Browse files

Add idhm_e route

parent 456ee9ae
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!59Idhm e route
Pipeline #
......@@ -30,6 +30,8 @@ const classroom = require('./classroom');
const teacher = require('./teacher');
const idhme = require('./idhme');
api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API is running' });
});
......@@ -46,5 +48,6 @@ api.use('/school', cache('15 day'), school);
api.use('/spatial', cache('1 day'), spatial);
api.use('/classroom', cache('15 day'), classroom);
api.use('/teacher', cache('1 day'), teacher);
api.use('/idhme', cache('15 day'), idhme);
module.exports = api;
const express = require('express');
const idhmeApp = express.Router();
const libs = `${process.cwd()}/libs`;
const squel = require('squel');
const query = require(`${libs}/middlewares/query`);
const response = require(`${libs}/middlewares/response`);
const id2str = require(`${libs}/middlewares/id2str`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
let rqf = new ReqQueryFields();
rqf.addField({
name: 'filter',
field: false,
where: true
}).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'
}
});
idhmeApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0) {
res.status(400);
next({
status: 400,
message: 'Wrong/No filter specified'
});
}
req.sql.from('adh_idh')
.field('adh_idh.idhm_e', 'IDHME')
.field('adh_idh.ano_censo', 'year')
.field('adh_idh.estado_id', 'state_id')
.field('adh_idh.municipio_id', 'city_id');
next();
}, query, response('idhme'));
module.exports = idhmeApp;
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