From dacd3280624004cf57bff5e6e241a0d6b90bced6 Mon Sep 17 00:00:00 2001 From: Gabriel Ruschel <grc15@inf.ufpr.br> Date: Fri, 30 Jun 2017 11:37:31 -0300 Subject: [PATCH] Fix state filter --- src/libs/routes/idhme.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libs/routes/idhme.js b/src/libs/routes/idhme.js index cd60b54f..9791fb07 100644 --- a/src/libs/routes/idhme.js +++ b/src/libs/routes/idhme.js @@ -45,12 +45,12 @@ rqf.addField({ relation: '=', type: 'integer', field: 'estado_id', - table: 'adh_idh' + table: 'adh_idh_uf' }, join: { primary: 'id', foreign: 'estado_id', - foreignTable: 'adh_idh' + foreignTable: 'adh_idh_uf' } }).addValue({ name: 'year', @@ -73,12 +73,20 @@ idhmeApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { message: 'Wrong/No filter specified' }); } - req.sql.from('adh_idh') + if ("state" in req.filter) { + // console.log("sim"); + req.sql.from('adh_idh_uf') + .field('adh_idh_uf.idhm_e', 'IDHME') + .field('adh_idh_uf.ano_censo', 'year') + .field('adh_idh_uf.estado_id', 'state_id'); + next(); + } else if ("city" in req.filter) { + 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(); + next(); + } }, query, response('idhme')); module.exports = idhmeApp; -- GitLab