diff --git a/src/libs/convert/admDependencyPub.js b/src/libs/convert/admDependencyPub.js new file mode 100644 index 0000000000000000000000000000000000000000..0522b2373916c27d0aa8531435d24d9c901cd96b --- /dev/null +++ b/src/libs/convert/admDependencyPub.js @@ -0,0 +1,32 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-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. + +simcaq-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 simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function admDependencyPub(id) { + switch (id) { + case 1: + return 'Rede pública'; + case 2: + return 'Rede estadual'; + case 3: + return 'Rede municipal'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index b59f64631d18edfdae229847f49ae91aa7252f6e..43cc1e0f9ed5edfd32a05c56ab665410034ec5b5 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -96,6 +96,7 @@ const diffLocation = require(`${libs}/convert/diffLocation`); const peePorCategoria = require(`${libs}/convert/peePorCategoria`); const pee = require(`${libs}/convert/booleanVariable`); const shift = require(`${libs}/convert/shift`); +const admDependencyPub = require(`${libs}/convert/admDependencyPub`); const ids = { gender_id: gender, @@ -107,6 +108,7 @@ const ids = { education_level_short_id: educationLevelShort, adm_dependency_id: admDependency, adm_dependency_detailed_id: admDependencyPriv, + adm_dependency_public_id: admDependencyPub, location_id: location, rural_location_id: ruralLocation, location_detailed_id: ruralLocation, @@ -298,5 +300,6 @@ module.exports = { diffLocation, peePorCategoria, pee, - shift + shift, + admDependencyPub }; diff --git a/src/libs/routes_v2/api.js b/src/libs/routes_v2/api.js index f680458493cd8cbea407c9d9730a4eb7498a113b..33822b8281231e04f15986fb66bacbb01204857e 100644 --- a/src/libs/routes_v2/api.js +++ b/src/libs/routes_v2/api.js @@ -140,6 +140,8 @@ const simcaqEnrollmentDiagnosis = require(`${libs}/routes_v2/simcaqEnrollmentDia const simcaqSecondReport = require(`${libs}/routes_v2/simcaqSecondReport`); +const simcaqDivisionOfResponsibility = require(`${libs}/routes_v2/simcaqDivisionOfResponsibility`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v2 is running' }); }); @@ -201,5 +203,6 @@ api.use('/course_students', courseStudents); api.use('/simcaq_first_report', simcaqFirstReport); api.use('/simcaq_enrollment_diagnosis', simcaqEnrollmentDiagnosis); api.use('/simcaq_second_report', simcaqSecondReport); +api.use('/simcaq_division_of_responsibility', simcaqDivisionOfResponsibility); module.exports = api; diff --git a/src/libs/routes_v2/simcaqDivisionOfResponsibility.js b/src/libs/routes_v2/simcaqDivisionOfResponsibility.js new file mode 100644 index 0000000000000000000000000000000000000000..e115ed41c0731281a0e5b36671846b6c0e79fbd5 --- /dev/null +++ b/src/libs/routes_v2/simcaqDivisionOfResponsibility.js @@ -0,0 +1,127 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-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. + +simcaq-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 simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +const express = require('express'); + +const simcaqDivisionOfResponsibilityApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const reqBody = require(`${libs}/middlewares/reqBody`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +const id2str = require(`${libs}/middlewares/id2str`); + +simcaqDivisionOfResponsibilityApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'simcaq_divisao_de_responsabilidade' + } +}, 'dims').addValue({ + name: 'state', + table: 'estado', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'simcaq_divisao_de_responsabilidade' + } +}, 'dims').addValue({ + name: 'school', + table: 'escola_agregada', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'escola_id', + foreignTable: 'simcaq_divisao_de_responsabilidade' + } +}, 'dims').addValue({ + name: 'education_level_short_id', + table: 'simcaq_divisao_de_responsabilidade', + tableField: 'etapa', + where: { + relation: '=', + type: 'integer', + field: 'etapa' + } +}).addValue({ + name: 'adm_dependency_public_id', + table: 'simcaq_divisao_de_responsabilidade', + tableField: 'rede', + where: { + relation: '=', + type: 'integer', + field: 'rede' + } +}); + +simcaqDivisionOfResponsibilityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_divisao_de_responsabilidade') + .field('SUM(simcaq_divisao_de_responsabilidade.total_matriculas)', 'enrollments') + .field('simcaq_divisao_de_responsabilidade.etapa', 'education_level_short_id') + .field('simcaq_divisao_de_responsabilidade.rede', 'adm_dependency_public_id') + .group('simcaq_divisao_de_responsabilidade.etapa') + .group('simcaq_divisao_de_responsabilidade.rede'); + next(); +}, query, id2str.transform(), response('divisionOfResponsibility')); + +module.exports = simcaqDivisionOfResponsibilityApp;