From 4944e77e58b30fa6868c197acc4410257147a377 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Tozatti=20Risso?= <jvtr12@c3sl.ufpr.br>
Date: Wed, 3 Aug 2016 14:17:47 -0300
Subject: [PATCH] Fix enrollments route response to comply with tests

---
 libs/routes/api.js | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libs/routes/api.js b/libs/routes/api.js
index 16105a85..b5492602 100644
--- a/libs/routes/api.js
+++ b/libs/routes/api.js
@@ -89,7 +89,7 @@ router.get('/enrollments', function(req, res, next) {
     const params = req.query;
     if (typeof params.aggregate !== 'undefined' && params.aggregate === 'region') {
         log.debug('Using enrollments query for regions');
-        req.sqlQuery = 'SELECT r.nome, COALESCE(SUM(t.num_matriculas), 0) AS total '
+        req.sqlQuery = 'SELECT r.nome AS name, COALESCE(SUM(t.num_matriculas), 0) AS total '
             + 'FROM regioes AS r '
             + 'INNER JOIN estados AS e ON r.pk_regiao_id = e.fk_regiao_id '
             + 'INNER JOIN municipios AS m ON e.pk_estado_id = m.fk_estado_id '
@@ -130,7 +130,7 @@ router.get('/enrollments', function(req, res, next) {
     const params = req.query;
     if (typeof params.aggregate !== 'undefined' && params.aggregate === 'state') {
         log.debug('Using enrollments query for states');
-        req.sqlQuery = 'SELECT e.nome, COALESCE(SUM(t.num_matriculas), 0) as total '
+        req.sqlQuery = 'SELECT e.nome AS name, COALESCE(SUM(t.num_matriculas), 0) as total '
             + 'FROM estados AS e '
             + 'INNER JOIN municipios AS m ON m.fk_estado_id = e.pk_estado_id '
             + 'LEFT OUTER JOIN turmas AS t ON ('
@@ -172,7 +172,7 @@ router.get('/enrollments', function(req, res, next) {
     const params = req.query;
     if (typeof params.aggregate !== 'undefined' && params.aggregate === 'city') {
         log.debug('Using enrollments query for cities');
-        req.sqlQuery = 'SELECT m.nome, COALESCE(SUM(t.num_matriculas), 0) as total '
+        req.sqlQuery = 'SELECT m.nome AS name, COALESCE(SUM(t.num_matriculas), 0) as total '
             + 'FROM municipios AS m '
             + 'LEFT OUTER JOIN turmas AS t ON ( '
             + 'm.pk_municipio_id = t.fk_municipio_id';
@@ -213,7 +213,7 @@ router.get('/enrollments', function(req, res, next) {
     const params = req.query;
     if (typeof params.aggregate === 'undefined') {
         log.debug('Using enrollments query for the whole country');
-        req.sqlQuery = 'SELECT \'Brasil\', COALESCE(SUM(t.num_matriculas),0) AS total '
+        req.sqlQuery = 'SELECT \'Brasil\' AS name, COALESCE(SUM(t.num_matriculas),0) AS total '
             + 'FROM turmas AS t';
         req.sqlQueryParams = [];
 
-- 
GitLab