diff --git a/libs/routes/api.js b/libs/routes/api.js index 16105a85d87e3afd2dd9120f28d2636f4503861b..b5492602a09efee0c405b97b6cded6bfb3e64038 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 = [];