From 8ddda71c340f1ee9b46d935b4f68c55c40838c15 Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Tue, 22 May 2018 10:51:24 -0300
Subject: [PATCH] Add state_id to infrastructure dimension

---
 CHANGELOG.md                      |  4 ++++
 src/libs/routes/infrastructure.js | 28 ++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f45fab7f..ed4b3d28 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/)
 and this project adheres to [Semantic Versioning](http://semver.org/).
 
+## 1.2.1 - 2018-05-22
+### Changed
+- Add state id in infrastructure
+
 ## 1.2.0 - 2018-05-21
 ### Added
 - Classroom count route
diff --git a/src/libs/routes/infrastructure.js b/src/libs/routes/infrastructure.js
index e201e1f4..290bf1a0 100644
--- a/src/libs/routes/infrastructure.js
+++ b/src/libs/routes/infrastructure.js
@@ -108,8 +108,8 @@ rqf.addField({
 }, 'dims').addValueToField({
     name: 'city',
     table: 'municipio',
-    tableField: 'nome',
-    resultField: 'city_name',
+    tableField: 'id',
+    resultField: 'city_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -121,11 +121,11 @@ rqf.addField({
         foreign: 'municipio_id',
         foreignTable: 'escola'
     }
-}, 'filter').addValue({
+}, 'filter').addValueToField({
     name: 'state',
     table: 'estado',
-    tableField: 'nome',
-    resultField: 'state_name',
+    tableField: ['nome', 'id'],
+    resultField: ['state_name', 'state_id'],
     where: {
         relation: '=',
         type: 'integer',
@@ -137,7 +137,23 @@ rqf.addField({
         foreign: 'estado_id',
         foreignTable: 'escola'
     }
-}).addValue({
+}, 'dims').addValueToField({
+    name: 'state',
+    table: 'estado',
+    tableField: 'id',
+    resultField: 'state_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'estado_id',
+        table: 'escola'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'estado_id',
+        foreignTable: 'escola'
+    }
+}, 'filter').addValue({
     name: 'region',
     table: 'regiao',
     tableField: 'nome',
-- 
GitLab