From 72b70404ce087075bb2c21dcc54f2826fb7c7551 Mon Sep 17 00:00:00 2001
From: Fernando Erd <fce15@inf.ufpr.br>
Date: Mon, 10 Jul 2017 11:29:33 -0300
Subject: [PATCH] Fix - Route test idhm and idhmr

---
 src/libs/routes/idhm.js  | 83 +++++++++++++++++++++-------------------
 src/libs/routes/idhmr.js | 36 +++++++++--------
 2 files changed, 65 insertions(+), 54 deletions(-)

diff --git a/src/libs/routes/idhm.js b/src/libs/routes/idhm.js
index 5248246a..3181e676 100644
--- a/src/libs/routes/idhm.js
+++ b/src/libs/routes/idhm.js
@@ -132,50 +132,55 @@ rqf.addField({
 idhmApp.get('/', rqf.parse(), (req, res, next) => {
   log.debug(req.sql.toParam());
   if((Object.keys(req.filter).length === 0) && (Object.keys(req.dims).length === 0)) {
-    res.status(400);
-    next({
-        status: 400,
-        message: 'Wrong/No filter specified'
-    });
+      res.status(400);
+      next({
+          status: 400,
+          message: 'Wrong/No filter specified'
+      });
   }
   if ("state" in req.filter) {
-    console.log("BBBBB");
-    req.sql.from('adh_idh_uf')
-    .field('adh_idh_uf.idhm', 'total')
-    .field('adh_idh_uf.ano_censo', 'year')
-    .field('adh_idh_uf.estado_id', 'state_id')
-    .group('adh_idh_uf.idhm')
-    .group('adh_idh_uf.ano_censo')
-    .group('adh_idh_uf.estado_id')
+      console.log("BBBBB");
+      req.sql.from('adh_idh_uf')
+      .field('adh_idh_uf.idhm', 'total')
+      .field('adh_idh_uf.ano_censo', 'year')
+      .field('adh_idh_uf.estado_id', 'state_id')
+      .group('adh_idh_uf.idhm')
+      .group('adh_idh_uf.ano_censo')
+      .group('adh_idh_uf.estado_id')
   } else if ("state" in req.dims) {
-    console.log("AAAAAAAAA");
-    req.sql.from('adh_idh')
-    .field('adh_idh.idhm', 'total')
-    .field('adh_idh.ano_censo', 'year')
-    .field('adh_idh.municipio_id', 'city_id')
-    .field('adh_idh.estado_id', 'state_id')
-    .group('adh_idh.idhm')
-    .group('adh_idh.ano_censo')
-    .group('adh_idh.municipio_id')
-    .group('adh_idh.estado_id')
+      console.log("AAAAAAAAA");
+      req.sql.from('adh_idh')
+      .field('adh_idh.idhm', 'total')
+      .field('adh_idh.ano_censo', 'year')
+      .field('adh_idh.municipio_id', 'city_id')
+      .field('adh_idh.estado_id', 'state_id')
+      .group('adh_idh.idhm')
+      .group('adh_idh.ano_censo')
+      .group('adh_idh.municipio_id')
+      .group('adh_idh.estado_id')
    } else if ("city" in req.filter) {
-     req.sql.from('adh_idh')
-     .field('adh_idh.idhm', 'total')
-     .field('adh_idh.ano_censo', 'year')
-     .field('adh_idh.municipio_id', 'city_id')
-     .group('adh_idh.idhm')
-     .group('adh_idh.ano_censo')
-     .group('adh_idh.municipio_id')
+       req.sql.from('adh_idh')
+       .field('adh_idh.idhm', 'total')
+       .field('adh_idh.ano_censo', 'year')
+       .field('adh_idh.municipio_id', 'city_id')
+       .group('adh_idh.idhm')
+       .group('adh_idh.ano_censo')
+       .group('adh_idh.municipio_id')
    } else if ("city" in req.dims) {
-        req.sql.from('adh_idh')
-        .field('adh_idh.idhm', 'total')
-        .field('adh_idh.ano_censo', 'year')
-        .field('adh_idh.municipio_id', 'city_id')
-        .group('adh_idh.idhm')
-        .group('adh_idh.ano_censo')
-        .group('adh_idh.municipio_id')
-        .group('adh_idh.estado_id')
-      }
+          req.sql.from('adh_idh')
+          .field('adh_idh.idhm', 'total')
+          .field('adh_idh.ano_censo', 'year')
+          .field('adh_idh.municipio_id', 'city_id')
+          .group('adh_idh.idhm')
+          .group('adh_idh.ano_censo')
+          .group('adh_idh.municipio_id')
+          .group('adh_idh.estado_id')
+    } else {
+        next({
+            status: 400,
+            message: 'Wrong/No filter specified'
+        });
+    }
    next();
 }, rqf.build(),query, response('idhm'));
 
diff --git a/src/libs/routes/idhmr.js b/src/libs/routes/idhmr.js
index ca240d17..48973ec6 100644
--- a/src/libs/routes/idhmr.js
+++ b/src/libs/routes/idhmr.js
@@ -108,23 +108,29 @@ rqf.addField({
 idhmrApp.get('/', rqf.parse(), (req, res, next) => {
   log.debug(req.sql.toParam());
   if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0 ) {
-    res.status(400);
-    next({
-        status: 400,
-        message: 'Wrong/No filter specified'
-    });
+      res.status(400);
+      next({
+          status: 400,
+          message: 'Wrong/No filter specified'
+      });
   }
   if ("state" in req.filter) {
-    req.sql.from('adh_idh_uf')
-    .field('adh_idh_uf.idhm_r', 'total')
-    .field('adh_idh_uf.ano_censo', 'year')
-    .field('adh_idh_uf.estado_id', 'state_id');
-   } else if ("city" in req.filter) {
-     req.sql.from('adh_idh')
-     .field('adh_idh.idhm_r', 'total')
-     .field('adh_idh.ano_censo', 'year')
-     .field('adh_idh.municipio_id', 'city_id');
-  }
+      req.sql.from('adh_idh_uf')
+      .field('adh_idh_uf.idhm_r', 'total')
+      .field('adh_idh_uf.ano_censo', 'year')
+      .field('adh_idh_uf.estado_id', 'state_id');
+  } else if ("city" in req.filter) {
+      req.sql.from('adh_idh')
+      .field('adh_idh.idhm_r', 'total')
+      .field('adh_idh.ano_censo', 'year')
+      .field('adh_idh.municipio_id', 'city_id');
+  } else {
+        next({
+            status: 400,
+            message: 'Wrong/No filter specified'
+        });
+    }
+
   next();
 }, rqf.build(),query, response('idhmr'));
 
-- 
GitLab