From 9b5d5cd7a5a8f7c691151aeb1b014ce5460c5985 Mon Sep 17 00:00:00 2001 From: Gabriel Ruschel <grc15@inf.ufpr.br> Date: Wed, 26 Jul 2017 11:36:26 -0300 Subject: [PATCH] Fix dims and filter queries --- src/libs/routes/idhme.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/libs/routes/idhme.js b/src/libs/routes/idhme.js index d7764735..9667d5b2 100644 --- a/src/libs/routes/idhme.js +++ b/src/libs/routes/idhme.js @@ -122,33 +122,25 @@ rqf.addField({ }); idhmeApp.get('/', rqf.parse(), (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' - }); - } - if (!("state" in req.filter) && !("city" in req.filter)) { - next({ - status: 400, - message: 'Wrong/No filter specified' - }); - } - if ("city" in req.filter) { + if (("city" in req.dims) || ("city" in req.filter)) { req.sql.from('adh_idh') .field('adh_idh.idhm_e', 'total') .field('adh_idh.ano_censo', 'year') - .field('adh_idh.municipio_id', 'city_id'); + .field('adh_idh.municipio_id', 'city_id') + .group('adh_idh.idhm_e') + .group('adh_idh.ano_censo') + .group('adh_idh.municipio_id'); } else { - // console.log("sim"); req.sql.from('adh_idh_uf') .field('adh_idh_uf.idhm_e', 'total') .field('adh_idh_uf.ano_censo', 'year') - .field('adh_idh_uf.estado_id', 'state_id'); + .field('adh_idh_uf.estado_id', 'state_id') + .group('adh_idh_uf.idhm_e') + .group('adh_idh_uf.ano_censo') + .group('adh_idh_uf.estado_id'); } next(); -}, rqf.build(), query, response('idhme')); +}, rqf.build(), query, id2str.transform(), response('idhme')); module.exports = idhmeApp; -- GitLab