From 9a6bb2b638719d613ec24baaba0cd9b9ad171951 Mon Sep 17 00:00:00 2001
From: Lucas Gabriel Lima <lgl15@inf.ufpr.br>
Date: Tue, 4 Jul 2017 09:41:57 -0300
Subject: [PATCH] add region to rqf values

---
 src/libs/routes/population.js | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/libs/routes/population.js b/src/libs/routes/population.js
index fe122d9b..90f57134 100644
--- a/src/libs/routes/population.js
+++ b/src/libs/routes/population.js
@@ -65,6 +65,22 @@ rqf.addField({
         foreign: 'estado_id',
         foreignTable: 'ibge_populacao'
     }
+}).addValue({
+    name: 'region',
+    table: 'regiao',
+    tableField: 'nome',
+    resultField: 'region_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'regiao_id',
+        table: 'ibge_populacao'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'regiao_id',
+        foreignTable: 'ibge_populacao'
+    }
 }).addValue({
     name: 'min_year',
     table: 'ibge_populacao',
@@ -98,13 +114,12 @@ populationApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
    .group('ibge_populacao.ano_censo')
    next();
 }, query, (req, res, next) => {
-    let somapop = 0;
-    for (var i = 0; i < req.result.length; i++) {
-        somapop += req.result[i].population;
-    }
-
-    req.result = [{population: somapop, year: req.result[0].year}];
-    console.log(req.params);
+    // let somapop = 0;
+    // for (var i = 0; i < req.result.length; i++) {
+    //     somapop += req.result[i].population;
+    // }
+    //
+    // req.result = [{population: somapop, year: req.result[0].year}];
     next()
 }, id2str.transform(true), response('population'));
 
-- 
GitLab