From 21f6eeefd2aaea33f7861ab20f0104da0883d05b Mon Sep 17 00:00:00 2001 From: Vytor Calixto <vytorcalixto@gmail.com> Date: Wed, 18 Apr 2018 10:26:28 -0300 Subject: [PATCH] :bug: Fix bug in pibpercapita route --- CHANGELOG.md | 4 ++++ src/libs/routes/pibpercapita.js | 30 ++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 739191bc..39d05f25 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.0.2 - 2018-04-18 +### Changed +- Fixed bug in pibpercapita route + ## 1.0.1 - 2018-03-15 ### Changed - Fix missing school id in teacher and class routes diff --git a/src/libs/routes/pibpercapita.js b/src/libs/routes/pibpercapita.js index 10e03b0f..57b70898 100644 --- a/src/libs/routes/pibpercapita.js +++ b/src/libs/routes/pibpercapita.js @@ -86,8 +86,8 @@ rqf.addField({ }).addValue({ name: 'state', table: 'estado', - tableField: 'nome', - resultField: 'state_name', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], where: { relation: '=', type: 'integer', @@ -163,21 +163,23 @@ pibpercapitaApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .order('ibge_pib.ano_censo') } next(); -}, query, addMissing(rqf), id2str.transform(false), (req, res, next) => { +}, query, (req, res, next) => { req.result.forEach((i) => { - let value = i.total; - let res = value.toString().split("."); - //rounding decimal. - let decimal = Math.round(res[1].toString().substring(0,2) + (".") + res[1].toString().substring(2,3)); - //case 0 after comma - if (res[1].toString().substring(0,1) == 0) { - i.total = parseFloat(res[0] + "." + "0" + decimal); - } else { - i.total = parseFloat(res[0] + "." + decimal); - } + let value = i.total; + console.log(i.total); + let res = value.toString().split("."); + //rounding decimal. + let decimal = Math.round(res[1].toString().substring(0,2) + (".") + res[1].toString().substring(2,3)); + //case 0 after comma + if (res[1].toString().substring(0,1) == 0) { + i.total = parseFloat(res[0] + "." + "0" + decimal); + } else { + i.total = parseFloat(res[0] + "." + decimal); + } + console.log(i.total); }); next(); - }, response("pibpercapita")); + }, addMissing(rqf), id2str.transform(false), response("pibpercapita")); module.exports = pibpercapitaApp; -- GitLab