From 7764533213c8d7c49e6617a26e79b1512b5b2e46 Mon Sep 17 00:00:00 2001
From: Nicollas <ns17@inf.ufpr.br>
Date: Fri, 9 Oct 2020 11:22:39 -0300
Subject: [PATCH] creating/fixing indigenous schools,enrollment and territorial
 routes

---
 .../routes/SMPPIR/indigenas_enrollment.js     | 145 ++++++++++++++++++
 src/libs/routes/SMPPIR/indigenas_schools.js   | 145 ++++++++++++++++++
 .../routes/SMPPIR/indigenas_territorial.js    | 125 +++++++++++++++
 src/libs/routes/api.js                        |   9 +-
 4 files changed, 423 insertions(+), 1 deletion(-)
 create mode 100644 src/libs/routes/SMPPIR/indigenas_enrollment.js
 create mode 100644 src/libs/routes/SMPPIR/indigenas_schools.js
 create mode 100644 src/libs/routes/SMPPIR/indigenas_territorial.js

diff --git a/src/libs/routes/SMPPIR/indigenas_enrollment.js b/src/libs/routes/SMPPIR/indigenas_enrollment.js
new file mode 100644
index 00000000..40408fba
--- /dev/null
+++ b/src/libs/routes/SMPPIR/indigenas_enrollment.js
@@ -0,0 +1,145 @@
+'use strict';
+
+/*
+Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of SMPPIR-Node.
+
+SMPPIR-Node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+SMPPIR-Node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with SMPPIR-Node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+var express = require('express');
+
+var indigenasSchoolsApp = express.Router();
+
+var libs = process.cwd() + '/libs';
+
+var squel = require('squel');
+
+var query = require(libs + '/middlewares/query').query;
+
+var response = require(libs + '/middlewares/response');
+
+var ReqQueryFields = require(libs + '/middlewares/reqQueryFields');
+
+var rqf = new ReqQueryFields();
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'year',
+    table: 'indigenas_schools_ag',
+    tableField: 'ano_censo',
+    resultField: 'ano_censo',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'localizacao_diferenciada',
+    table: 'indigenas_schools_ag',
+    tableField: 'localizacao_diferenciada_id',
+    resultField: 'cod_localizacao_diferenciada',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localizacao_diferenciada_id'
+    }
+}).addValue({
+    name: 'agua',
+    table: 'indigenas_schools_ag',
+    tableField: 'agua_rede_publica',
+    resultField: 'abastecimento_agua_rede_publica',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'agua_rede_publica'
+    }
+}).addValue({
+    name: 'energia',
+    table: 'indigenas_schools_ag',
+    tableField: 'energia_rede_publica',
+    resultField: 'abastecimento_energia_rede_publica',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'energia_rede_publica'
+    }
+}).addValue({
+    name: 'esgoto',
+    table: 'indigenas_schools_ag',
+    tableField: 'esgoto_rede_publica',
+    resultField: 'esgotamento_snaitario_rede_publica',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'esgoto_rede_publica'
+    }
+}).addValue({
+    name: 'lixo',
+    table: 'indigenas_schools_ag',
+    tableField: 'lixo_coleta_periodica',
+    resultField: 'coleta_lixo_periodica',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'lixo_coleta_periodica'
+    }
+}).addValue({
+    name: 'uf',
+    table: 'indigenas_schools_ag',
+    tableField: 'sigla',
+    resultField: 'sigla_uf',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'sigla'
+    }
+}).addValue({
+    name: 'id',
+    table: 'indigenas_schools_ag',
+    tableField: 'id',
+    resultField: 'escola_id',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'id'
+    }
+}).addValue({
+    name: 'etapa_ensino',
+    table: 'indigenas_schools_ag',
+    tableField: 'etapa_ensino',
+    resultField: 'etapa_ensino',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'etapa_ensino'
+    }
+});
+
+indigenasSchoolsApp.get('/', rqf.parse(), rqf.build(), function (req, res, next) {
+    console.log(req.sql.toString());
+    req.sql.field('SUM(total) AS Total').from('terras_indigenas');
+    next();
+}, query, response('terras_ind'));
+
+module.exports = indigenasSchoolsApp;
\ No newline at end of file
diff --git a/src/libs/routes/SMPPIR/indigenas_schools.js b/src/libs/routes/SMPPIR/indigenas_schools.js
new file mode 100644
index 00000000..a2c36ed6
--- /dev/null
+++ b/src/libs/routes/SMPPIR/indigenas_schools.js
@@ -0,0 +1,145 @@
+'use strict';
+
+/*
+Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of SMPPIR-Node.
+
+SMPPIR-Node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+SMPPIR-Node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with SMPPIR-Node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+var express = require('express');
+
+var indigenasSchoolsApp = express.Router();
+
+var libs = process.cwd() + '/libs';
+
+var squel = require('squel');
+
+var query = require(libs + '/middlewares/query').query;
+
+var response = require(libs + '/middlewares/response');
+
+var ReqQueryFields = require(libs + '/middlewares/reqQueryFields');
+
+var rqf = new ReqQueryFields();
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'year',
+    table: 'indigenas_schools_ag',
+    tableField: 'ano_censo',
+    resultField: 'ano_censo',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'localizacao_diferenciada',
+    table: 'indigenas_schools_ag',
+    tableField: 'localizacao_diferenciada_id',
+    resultField: 'cod_localizacao_diferenciada',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'localizacao_diferenciada_id'
+    }
+}).addValue({
+    name: 'agua',
+    table: 'indigenas_schools_ag',
+    tableField: 'agua_rede_publica',
+    resultField: 'abastecimento_agua_rede_publica',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'agua_rede_publica'
+    }
+}).addValue({
+    name: 'energia',
+    table: 'indigenas_schools_ag',
+    tableField: 'energia_rede_publica',
+    resultField: 'abastecimento_energia_rede_publica',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'energia_rede_publica'
+    }
+}).addValue({
+    name: 'esgoto',
+    table: 'indigenas_schools_ag',
+    tableField: 'esgoto_rede_publica',
+    resultField: 'esgotamento_snaitario_rede_publica',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'esgoto_rede_publica'
+    }
+}).addValue({
+    name: 'lixo',
+    table: 'indigenas_schools_ag',
+    tableField: 'lixo_coleta_periodica',
+    resultField: 'coleta_lixo_periodica',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'lixo_coleta_periodica'
+    }
+}).addValue({
+    name: 'uf',
+    table: 'indigenas_schools_ag',
+    tableField: 'sigla',
+    resultField: 'sigla_uf',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'sigla'
+    }
+}).addValue({
+    name: 'id',
+    table: 'indigenas_schools_ag',
+    tableField: 'id',
+    resultField: 'escola_id',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'id'
+    }
+}).addValue({
+    name: 'etapa_ensino',
+    table: 'indigenas_schools_ag',
+    tableField: 'etapa_ensino',
+    resultField: 'etapa_ensino',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'etapa_ensino'
+    }
+});
+
+indigenasSchoolsApp.get('/', rqf.parse(), rqf.build(), function (req, res, next) {
+    console.log(req.sql.toString());
+    req.sql.field('COUNT(distinct id) AS Total').from('terras_indigenas');
+    next();
+}, query, response('terras_ind'));
+
+module.exports = indigenasSchoolsApp;
\ No newline at end of file
diff --git a/src/libs/routes/SMPPIR/indigenas_territorial.js b/src/libs/routes/SMPPIR/indigenas_territorial.js
new file mode 100644
index 00000000..1336a973
--- /dev/null
+++ b/src/libs/routes/SMPPIR/indigenas_territorial.js
@@ -0,0 +1,125 @@
+'use strict';
+
+/*
+Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of SMPPIR-Node.
+
+SMPPIR-Node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+SMPPIR-Node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with SMPPIR-Node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+var express = require('express');
+
+var indigenasTerritorialApp = express.Router();
+
+var libs = process.cwd() + '/libs';
+
+var squel = require('squel');
+
+var query = require(libs + '/middlewares/query').query;
+
+var response = require(libs + '/middlewares/response');
+
+var ReqQueryFields = require(libs + '/middlewares/reqQueryFields');
+
+var rqf = new ReqQueryFields();
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'year',
+    table: 'terras_indigenas',
+    tableField: 'ano',
+    resultField: 'ano_divulgacao',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'ano'
+    }
+}).addValue({
+    name: 'local_name',
+    table: 'terras_indigenas',
+    tableField: 'nome_terra',
+    resultField: 'nome_terra_indigena',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'nome_terra'
+    }
+}).addValue({
+    name: 'ethnic_name',
+    table: 'terras_indigenas',
+    tableField: 'nome_etnia',
+    resultField: 'etnia_indigena',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'nome_etnia'
+    }
+}).addValue({
+    name: 'uf',
+    table: 'terras_indigenas',
+    tableField: 'sigla_uf',
+    resultField: 'unidade_federativa',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'sigla_uf'
+    }
+}).addValue({
+    name: 'area',
+    table: 'terras_indigenas',
+    tableField: 'tamanho_superficie',
+    resultField: 'superficie(ha)',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'tamanho_superficie'
+    }
+}).addValue({
+    name: 'process_stage',
+    table: 'terras_indigenas',
+    tableField: 'fase_procedimento',
+    resultField: 'fase_do_procedimento',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'fase_procedimento'
+    }
+}).addValue({
+    name: 'modality',
+    table: 'terras_indigenas',
+    tableField: 'tipo_modalidade',
+    resultField: 'tipo_modalidade',
+    where: {
+        relation: '=',
+        type: 'string',
+        field: 'tipo_modalidade'
+    }
+});
+
+indigenasTerritorialApp.get('/', rqf.parse(), rqf.build(), function (req, res, next) {
+    console.log(req.sql.toString());
+    req.sql.field('COUNT(*) AS Total').from('terras_indigenas');
+    next();
+}, query, response('terras_ind'));
+
+module.exports = indigenasTerritorialApp;
\ No newline at end of file
diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js
index 053f3d31..239b5003 100644
--- a/src/libs/routes/api.js
+++ b/src/libs/routes/api.js
@@ -122,6 +122,10 @@ const indigenas_development = require(`${libs}/routes/indigenas_development`);
 
 const indigenas_rights =  require(`${libs}/routes/indigenas_rights`);
 
+const indigenas_schools = require(`${libs}/routes/SMPPIR/indigenas_schools`);
+
+const indigenas_enrollment = require(`${libs}/routes/SMPPIR/indigenas_enrollment`);
+
 api.get('/', (req, res) => {
     res.json({ msg: 'SMPPIR API is running' });
 });
@@ -170,6 +174,9 @@ api.use('/traditional_families', traditional_families)
 api.use('/traditional_families_people', traditional_families_people)
 api.use('/indigenas_infrastructure', indigenas_infrastructure)
 api.use('/indigenas_development', indigenas_development)
-api.use('/indigenas_rights', indigenas_rights)  
+api.use('/indigenas_rights', indigenas_rights)
+api.use('/indigenas_territorial', indigenas_territorial)
+api.use('/indigenas_schools', indigenas_schools)
+api.use('/indigenas_enrollment', indigenas_enrollment)
 
 module.exports = api;
-- 
GitLab