From 2f94eac60f818b84b3b64ff6682407f5ff2a04b3 Mon Sep 17 00:00:00 2001
From: es23 <es23@inf.ufpr.br>
Date: Wed, 2 Apr 2025 12:00:51 -0300
Subject: [PATCH] fix filters

---
 .../routes_v1/superiorEnrollmentAggregate.js  | 85 ++++++++++---------
 1 file changed, 43 insertions(+), 42 deletions(-)

diff --git a/src/libs/routes_v1/superiorEnrollmentAggregate.js b/src/libs/routes_v1/superiorEnrollmentAggregate.js
index e9a28788..7c1350c7 100644
--- a/src/libs/routes_v1/superiorEnrollmentAggregate.js
+++ b/src/libs/routes_v1/superiorEnrollmentAggregate.js
@@ -59,38 +59,33 @@ superiorEnrollmentAggregateApp.get('/years', (req, res, next) => {
     next();
 }, query, response('years'));
 
-superiorEnrollmentAggregateApp.get('/qtd_graduates', (req, res, next) => {
-    req.sql.from('curso_superior_agregado')
-    .field('DISTINCT SUM(curso_superior_agregado.qtd_concluintes)', 'qtd_graduates')
-    .where('curso_superior_agregado.ano_censo >= 2020')
-    next();
-    
-}, query, response('qtd_graduates'));
-
 superiorEnrollmentAggregateApp.get('/ies_name', (req, res, next) => {
     req.sql.from('curso_superior_agregado')
-    .field('DISTINCT curso_superior_agregado.cod_ies', 'ies_cod')
-    .field('curso_superior_agregado.nome_ies', 'ies_name')
+	.from('ies_ens_superior')
+    .field('DISTINCT curso_superior_agregado.cod_ies', 'id')
+    .field('ies_ens_superior.nome_ies', 'name')
+	.where('ies_ens_superior.cod_ies = curso_superior_agregado.cod_ies')
     .where('curso_superior_agregado.ano_censo >= 2020')
     next();
 }, query, response('ies_name'));
 
-superiorEnrollmentAggregateApp.get('/uf_agg', (req, res, next) => {
+superiorEnrollmentAggregateApp.get('/state', (req, res, next) => {
     req.sql.from('curso_superior_agregado')
-    .field('DISTINCT curso_superior_agregado.cod_uf', 'uf_cod')
-    .field('curso_superior_agregado.nome_uf', 'uf_name')
+    .field('DISTINCT curso_superior_agregado.cod_uf', 'id')
+    .field('curso_superior_agregado.nome_uf', 'name')
     .where('curso_superior_agregado.ano_censo >= 2020')
+	.where('curso_superior_agregado.nome_uf IS NOT NULL')
     next();
-}, query, response('uf_agg'));
+}, query, response('state'));
 
-superiorEnrollmentAggregateApp.get('/city_agg', (req, res, next) => {
+superiorEnrollmentAggregateApp.get('/city', (req, res, next) => {
     req.sql.from('curso_superior_agregado')
-    .field('DISTINCT curso_superior_agregado.cod_mun', 'city_cod')
-    .field('curso_superior_agregado.nome_mun', 'city_name')
+    .field('DISTINCT curso_superior_agregado.cod_mun', 'id')
+    .field('curso_superior_agregado.nome_mun', 'name')
     .where('curso_superior_agregado.ano_censo >= 2020')
     .order('curso_superior_agregado.cod_mun')
     next();
-}, query, response('city_agg'));
+}, query, response('city'));
 
 superiorEnrollmentAggregateApp.get('/tp_categ_adm', (req, res, next) => {
     req.result = []
@@ -101,7 +96,7 @@ superiorEnrollmentAggregateApp.get('/tp_categ_adm', (req, res, next) => {
         });
     }
     next();
-}, response('adm_dependency'));
+}, response('tp_categ_adm'));
 
 superiorEnrollmentAggregateApp.get('/cine_global', (req, res, next) => {
     req.result = [];
@@ -122,7 +117,7 @@ superiorEnrollmentAggregateApp.get('/cine_specific', (req, res, next) => {
             id: i,
             name: id2str.cineSpecific(i)
         };
-        if (obj.name !== id1str.cineSpecific(defaultCase)){
+        if (obj.name !== id2str.cineSpecific(defaultCase)){
             req.result.push(obj);
         }
     };
@@ -193,7 +188,7 @@ superiorEnrollmentAggregateApp.get('/academic_organization', (req, res, next) =>
     next();
 }, response('academic_organization'));
 
-superiorEnrollmentAggregateApp.get('/region_agg', (req, res, next) => {
+superiorEnrollmentAggregateApp.get('/region', (req, res, next) => {
     req.result = [];
     for (let i = 1; i <= 5; ++i) {
         req.result.push({
@@ -202,7 +197,7 @@ superiorEnrollmentAggregateApp.get('/region_agg', (req, res, next) => {
         })
     }
     next();
-}, response('region_agg'));
+}, response('region'));
 
 rqf.addField({
     name: 'filter',
@@ -236,7 +231,7 @@ rqf.addField({
     name: 'tp_categ_adm',
     table: 'curso_superior_agregado',
     tableField: 'tp_categ_adm',
-    resultField: 'tp_categ_adm',
+    resultField: 'tp_categ_adm_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -246,27 +241,27 @@ rqf.addField({
     name: 'cine_global',
     table: 'curso_superior_agregado',
     tableField: ['nome_cine_area_geral', 'cod_cine_area_geral'],
-    resultField: ['name_cine_global', 'cod_cine_global'],
+    resultField: ['cine_global_name', 'cine_global_id'],
     where: {
         relation: '=',
         type: 'integer',
         field: 'cod_cine_area_geral',
     },
 }).addValue({
-    name: 'cine_sp',
+    name: 'cine_specific',
     table: 'curso_superior_agregado',
     tableField: ['nome_cine_area_esp', 'cod_cine_area_esp'],
-    resultField: ['name_cine_sp', 'cod_cine_sp'],
+    resultField: ['cine_sp_name', 'cine_sp_id'],
     where: {
         relation: '=',
         type: 'integer',
         field: 'cod_cine_area_esp'
     }
 }).addValue({
-    name: 'cine_deatiled',
+    name: 'cine_detailed',
     table: 'curso_superior_agregado',
     tableField: ['nome_cine_area_detalhada', 'cod_cine_area_detalhada'],
-    resultField: ['name_cine_detailed', 'cod_cine_detailed'],
+    resultField: ['cine_detailed_name', 'cine_detailed_id'],
     where: {
         relation: '=',
         type: 'integer',
@@ -276,7 +271,7 @@ rqf.addField({
     name: 'graduates',
     table: 'curso_superior_agregado',
     tableField: 'qtd_concluintes',
-    resultField: 'graduates',
+    resultField: 'graduates_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -286,7 +281,7 @@ rqf.addField({
     name: 'disabled_students',
     table: 'curso_superior_agregado',
     tableField: 'qtd_aluno_deficiente',
-    resultField: 'disabled_students',
+    resultField: 'disabled_students_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -296,7 +291,7 @@ rqf.addField({
     name: 'academic_level',
     table: 'curso_superior_agregado',
     tableField: 'tp_grau_acad',
-    resultField: 'academic_level',
+    resultField: 'academic_level_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -306,7 +301,7 @@ rqf.addField({
     name: 'ies_name',
     table: 'ies_ens_superior',
     tableField: 'nome_ies',
-    resultField: 'ies_name',
+    resultField: 'ies_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -321,7 +316,7 @@ rqf.addField({
     name: 'modality',
     table: 'curso_superior_agregado',
     tableField: 'tp_modal_ens',
-    resultField: 'modality',
+    resultField: 'modality_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -331,37 +326,37 @@ rqf.addField({
     name: 'academic_organization',
     table: 'curso_superior_agregado',
     tableField: 'tp_org_acad',
-    resultField: 'academic_organization',
+    resultField: 'academic_organization_id',
     where: {
         relation: '=',
         type: 'integer',
         field: 'tp_org_acad'
     }
 }).addValue({
-    name: 'region_agg',
+    name: 'region',
     table: 'curso_superior_agregado',
     tableField: 'nome_reg',
-    resultField: 'reg_name',
+    resultField: 'reg_id',
     where: {
         relation: '=',
         type: 'integer',
         field: 'cod_reg'
     }
 }).addValue({
-    name: 'uf_agg',
+    name: 'state',
     table:  'curso_superior_agregado',
     tableField: 'nome_uf',
-    resultField: 'uf_name',
+    resultField: 'uf_id',
     where: {
         relation: '=',
         type: 'integer',
         field: 'cod_uf'
     }
 }).addValue({
-    name: 'city_agg',
+    name: 'city',
     table: 'curso_superior_agregado',
     tableField: 'nome_mun',
-    resultField: 'city_name',
+    resultField: 'city_id',
     where: {
         relation: '=',
         type: 'integer',
@@ -375,7 +370,7 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex
     req.sql.field('curso_superior_agregado.ano_censo', 'year');
 
     if (req.query.dims && req.query.dims.includes("ethnic_group")){
-        req.sql.field.field('sum(qtd_mat_branca)', 'total_branca')
+        req.sql.field('sum(qtd_mat_branca)', 'total_branca')
         .field('sum(qtd_mat_preta)', 'total_preta')
         .field('sum(qtd_mat_parda)', 'total_parda')
         .field('sum(qtd_mat_amarela)', 'total_amarela')
@@ -405,8 +400,14 @@ superiorEnrollmentAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, nex
         req.sql.field('sum(qtd_mat_diurno)', 'total_diurno')
         .field('sum(qtd_mat_noturno)', 'total_noturno');
     }
+	else if (req.query.dims && req.query.dims.includes("qtd_graduates_agg")){
+    	req.sql.field('SUM(curso_superior_agregado.qtd_concluintes)', 'total');
+	}
+	else if (req.query.dims && req.query.dims.includes("disabled_students_agg")){
+		req.sql.field('SUM(curso_superior_agregado.qtd_aluno_deficiente)', 'total')
+	}
     else {
-        req.sql.field('SUM(qtd_matriculas)', 'enrollment');
+        req.sql.field('SUM(qtd_matriculas)', 'total');
     }
     
     req.sql.from('curso_superior_agregado')
-- 
GitLab