Skip to content
Snippets Groups Projects
Unverified Commit 4944e77e authored by João Victor Risso's avatar João Victor Risso
Browse files

Fix enrollments route response to comply with tests

parent 1baf5471
No related branches found
No related tags found
1 merge request!7Refactor enrollments route to include query building
Pipeline #
...@@ -89,7 +89,7 @@ router.get('/enrollments', function(req, res, next) { ...@@ -89,7 +89,7 @@ router.get('/enrollments', function(req, res, next) {
const params = req.query; const params = req.query;
if (typeof params.aggregate !== 'undefined' && params.aggregate === 'region') { if (typeof params.aggregate !== 'undefined' && params.aggregate === 'region') {
log.debug('Using enrollments query for regions'); 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 ' + 'FROM regioes AS r '
+ 'INNER JOIN estados AS e ON r.pk_regiao_id = e.fk_regiao_id ' + '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 ' + '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) { ...@@ -130,7 +130,7 @@ router.get('/enrollments', function(req, res, next) {
const params = req.query; const params = req.query;
if (typeof params.aggregate !== 'undefined' && params.aggregate === 'state') { if (typeof params.aggregate !== 'undefined' && params.aggregate === 'state') {
log.debug('Using enrollments query for states'); 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 ' + 'FROM estados AS e '
+ 'INNER JOIN municipios AS m ON m.fk_estado_id = e.pk_estado_id ' + 'INNER JOIN municipios AS m ON m.fk_estado_id = e.pk_estado_id '
+ 'LEFT OUTER JOIN turmas AS t ON (' + 'LEFT OUTER JOIN turmas AS t ON ('
...@@ -172,7 +172,7 @@ router.get('/enrollments', function(req, res, next) { ...@@ -172,7 +172,7 @@ router.get('/enrollments', function(req, res, next) {
const params = req.query; const params = req.query;
if (typeof params.aggregate !== 'undefined' && params.aggregate === 'city') { if (typeof params.aggregate !== 'undefined' && params.aggregate === 'city') {
log.debug('Using enrollments query for cities'); 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 ' + 'FROM municipios AS m '
+ 'LEFT OUTER JOIN turmas AS t ON ( ' + 'LEFT OUTER JOIN turmas AS t ON ( '
+ 'm.pk_municipio_id = t.fk_municipio_id'; + 'm.pk_municipio_id = t.fk_municipio_id';
...@@ -213,7 +213,7 @@ router.get('/enrollments', function(req, res, next) { ...@@ -213,7 +213,7 @@ router.get('/enrollments', function(req, res, next) {
const params = req.query; const params = req.query;
if (typeof params.aggregate === 'undefined') { if (typeof params.aggregate === 'undefined') {
log.debug('Using enrollments query for the whole country'); 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'; + 'FROM turmas AS t';
req.sqlQueryParams = []; req.sqlQueryParams = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment