From 08f39caa8b42c5d4fd88f932b8d4296593098ed3 Mon Sep 17 00:00:00 2001
From: Glenda <gpt16@inf.ufpr.br>
Date: Wed, 27 Jun 2018 11:29:40 -0300
Subject: [PATCH] fix auxiliar route

---
 src/libs/routes/auxiliar.js | 69 +++++++++++++++----------------------
 1 file changed, 27 insertions(+), 42 deletions(-)

diff --git a/src/libs/routes/auxiliar.js b/src/libs/routes/auxiliar.js
index 7136eb5c..21e7c5f5 100644
--- a/src/libs/routes/auxiliar.js
+++ b/src/libs/routes/auxiliar.js
@@ -50,7 +50,6 @@ auxiliarApp.get('/source', (req, res, next) => {
     next();
 }, query, response('source'))
 
-// Dependência administrativa
 auxiliarApp.get('/adm_dependency_detailed', (req, res, next) => {
     req.result = [];
     for(let i = 1; i <= 6; ++i) {
@@ -62,7 +61,6 @@ auxiliarApp.get('/adm_dependency_detailed', (req, res, next) => {
     next();
 }, response('adm_dependency_detailed'));
 
-// Dependência administrativa com detalhamento das escolas privadas
 auxiliarApp.get('/adm_dependency', (req, res, next) => {
     req.result = [];
     for(let i = 1; i <= 4; ++i) {
@@ -74,7 +72,6 @@ auxiliarApp.get('/adm_dependency', (req, res, next) => {
     next();
 }, response('adm_dependency'));
 
-// Área da localidade
 auxiliarApp.get('/location', (req, res, next) => {
     req.result = [];
     for(let i = 1; i <= 2; ++i) {
@@ -86,7 +83,6 @@ auxiliarApp.get('/location', (req, res, next) => {
     next();
 }, response('location'));
 
-// Área da localidade por tipo de área rural
 auxiliarApp.get('/rural_location', (req, res, next) => {
     req.result = [
         {id: 1, name: "Urbana"},
@@ -99,7 +95,6 @@ auxiliarApp.get('/rural_location', (req, res, next) => {
     next();
 }, response('rural_location'));
 
-// Etapa e modalidade por segmento
 auxiliarApp.get('/education_level_mod', (req, res, next) => {
     req.result = [];
     for(let i = 1; i <= 11; ++i) {
@@ -116,7 +111,6 @@ auxiliarApp.get('/education_level_mod', (req, res, next) => {
     next();
 }, response('education_level_mod'));
 
-// Sexo
 auxiliarApp.get('/gender', (req, res, next) => {
     req.result = [
         {id: 1, name: 'Masculino'},
@@ -125,7 +119,6 @@ auxiliarApp.get('/gender', (req, res, next) => {
     next();
 }, response('gender'));
 
-// Raça/Cor
 auxiliarApp.get('/ethnic_group', (req, res, next) => {
     req.result = [];
     for(let i = 0; i <=5; ++i) {
@@ -137,7 +130,6 @@ auxiliarApp.get('/ethnic_group', (req, res, next) => {
     next();
 }, response('ethnic_group'));
 
-// Filtros
 rqf.addField({
     name: 'filter',
     field: false,
@@ -146,7 +138,6 @@ rqf.addField({
     name: 'dims',
     field: true,
     where: false
-// Dependência administrativa [CEBES013N0]
 }).addValue({
     name: 'adm_dependency',
     table: 'docente',
@@ -157,7 +148,6 @@ rqf.addField({
         type: 'integer',
         field: 'dependencia_adm_id'
     }
-// Dependência administrativa com detalhamento das escolas privadas [CEBES013T1]
 }).addValue({
     name: 'adm_dependency_detailed',
     table: 'docente',
@@ -168,7 +158,6 @@ rqf.addField({
         type: 'integer',
         field: 'dependencia_adm_priv'
     }
-// Etapa e modalidade por segmento [CEBDO009N0T1]
 }).addValue({
     name: 'education_level_mod',
     table: 'docente',
@@ -209,6 +198,16 @@ rqf.addField({
         foreign: 'escola_estado_id',
         foreignTable: 'docente'
     }
+}).addValue({
+    name: 'rural_location',
+    table: 'docente',
+    tableField: 'localidade_area_rural',
+    resultField: 'rural_location_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localidade_area_rural'
+    }
 }).addValueToField({
     name: 'city',
     table: 'municipio',
@@ -239,7 +238,6 @@ rqf.addField({
         foreign: 'escola_municipio_id',
         foreignTable: 'docente'
     }
-// Área da localidade [CEBES014N0]
 }, 'filter').addValue({
     name: 'location',
     table: 'docente',
@@ -250,17 +248,6 @@ rqf.addField({
         type: 'integer',
         field: 'cod_localizacao'
     }
-// Área da localidade por tipo de área rural [CEBES014T1]
-}).addValue({
-    name: 'rural_location',
-    table: 'docente',
-    tableField: 'localidade_area_rural',
-    resultField: 'rural_location_id',
-    where: {
-        relation: '=',
-        type: 'integer',
-        field: 'localidade_area_rural'
-    }
 }).addValue({
     name: 'min_year',
     table: 'docente',
@@ -281,7 +268,6 @@ rqf.addField({
         type: 'integer',
         field: 'ano_censo'
     }
-// Sexo [CEBDO008N0]
 }).addValue({
     name: 'gender',
     table: 'docente',
@@ -292,7 +278,6 @@ rqf.addField({
         type: 'integer',
         field: 'sexo'
     }
-// Cor/Raça [CEBDO009N0]
 }).addValue({
     name: 'ethnic_group',
     table: 'docente',
@@ -305,28 +290,28 @@ rqf.addField({
     }
 });
 
-// Lab dados
+// LDE
 auxiliarApp.get('/', rqf.parse(), (req, res, next) => {
-    req.sql.field('COUNT(DISTINCT docente.id)', 'total')
-    .field("'Brasil'", 'name')
-    .field('docente.ano_censo', 'year')
-    .from('docente')
-    .group('docente.ano_censo')
-    .order('docente.ano_censo')
-    .where('((docente.tipo_turma_id <= 3) AND (docente.dependencia_adm_id = 2 OR docente.dependencia_adm_id = 3) AND (docente.tipo_docente = 2))');
-    next();
+  req.sql.field('COUNT(DISTINCT docente.id)', 'total')
+  .field("'Brasil'", 'name')
+  .field('docente.ano_censo', 'year')
+  .from('docente')
+  .group('docente.ano_censo')
+  .order('docente.ano_censo')
+  .where('(docente.tipo_turma_id <= 3 AND docente.dependencia_adm_id > 1 AND docente.tipo_docente = 2)');
+  next();
 }, rqf.build(), query, addMissing(rqf), id2str.transform(), response('auxiliar'));
 
 // SimCAQ
 auxiliarApp.get('/count', rqf.parse(), (req, res, next) => {
-    req.sql.field('COUNT(DISTINCT docente.id)', 'total')
-    .field("'Brasil'", 'name')
-    .field('docente.ano_censo', 'year')
-    .from('docente')
-    .group('docente.ano_censo')
-    .order('docente.ano_censo')
-    .where('(docente.tipo_turma_id <= 3 AND docente.tipo_docente = 2)');
-    next();
+  req.sql.field('COUNT(DISTINCT docente.id)', 'total')
+  .field("'Brasil'", 'name')
+  .field('docente.ano_censo', 'year')
+  .from('docente')
+  .group('docente.ano_censo')
+  .order('docente.ano_censo')
+  .where('((docente.tipo_turma_id <= 3) AND (docente.dependencia_adm_id = 2 OR docente.dependencia_adm_id = 3) AND (docente.tipo_docente = 2))');
+  next();
 }, rqf.build(), query, addMissing(rqf), id2str.transform(), response('auxiliar'));
 
 auxiliarApp.get('/download', passport.authenticate('bearer', { session: false }), rqf.parse(), rqf.build(), download('docente', 'mapping_docente'));
-- 
GitLab