From 77581a804059851b3b611b14907db82340e15d57 Mon Sep 17 00:00:00 2001
From: Gabriel Ruschel <grc15@inf.ufpr.br>
Date: Wed, 2 Aug 2017 11:26:26 -0300
Subject: [PATCH] Fix idhme default

---
 src/libs/routes/idhme.js | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/libs/routes/idhme.js b/src/libs/routes/idhme.js
index 9667d5b2..5ce84d93 100644
--- a/src/libs/routes/idhme.js
+++ b/src/libs/routes/idhme.js
@@ -123,6 +123,14 @@ 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 (("city" in req.dims) || ("city" in req.filter)) {
         req.sql.from('adh_idh')
         .field('adh_idh.idhm_e', 'total')
@@ -131,7 +139,7 @@ idhmeApp.get('/', rqf.parse(), (req, res, next) => {
         .group('adh_idh.idhm_e')
         .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_e', 'total')
         .field('adh_idh_uf.ano_censo', 'year')
@@ -139,6 +147,12 @@ idhmeApp.get('/', rqf.parse(), (req, res, next) => {
         .group('adh_idh_uf.idhm_e')
         .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'));
-- 
GitLab