diff --git a/src/libs/routes/idhml.js b/src/libs/routes/idhml.js index be1ee7a3b7a0b00b7d914d0a9fe1d480034beae7..eb39779db0df0a47543266e013bd97bb3d4faf94 100644 --- a/src/libs/routes/idhml.js +++ b/src/libs/routes/idhml.js @@ -122,6 +122,13 @@ rqf.addField({ }); idhmlApp.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 (("city" in req.dims) || ("city" in req.filter)) { req.sql.from('adh_idh') @@ -131,7 +138,7 @@ idhmlApp.get('/', rqf.parse(), (req, res, next) => { .group('adh_idh.idhm_l') .group('adh_idh.ano_censo') .group('adh_idh.municipio_id'); - } else { + } else if (("state" in req.filter) || ("state" in req.dims) && !("city" in req.filter) && !("city" in req.dims)) { req.sql.from('adh_idh_uf') .field('adh_idh_uf.idhm_l', 'total') .field('adh_idh_uf.ano_censo', 'year') @@ -139,6 +146,12 @@ idhmlApp.get('/', rqf.parse(), (req, res, next) => { .group('adh_idh_uf.idhm_l') .group('adh_idh_uf.ano_censo') .group('adh_idh_uf.estado_id'); + } else { + res.status(400); + next({ + status: 400, + message: 'Wrong/No filter specified' + }); } next(); }, rqf.build(), query, id2str.transform(), response('idhme'));