diff --git a/src/libs/routes_v2/api.js b/src/libs/routes_v2/api.js index 071f8ffa54721b4f57b5181a563a926aaec8107f..cb19b9a4fa94e95c5073f1debdd9ff3cb9d3da63 100644 --- a/src/libs/routes_v2/api.js +++ b/src/libs/routes_v2/api.js @@ -138,6 +138,8 @@ const simcaqFirstReport = require(`${libs}/routes_v2/simcaqFirstReport`); const enrollmentDiagnosis = require(`${libs}/routes_v2/enrollment_diagnosis`); +const simcaqSecondReport = require(`${libs}/routes_v2/simcaqSecondReport`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v2 is running' }); }); @@ -198,5 +200,6 @@ api.use('/message', message); api.use('/course_students', courseStudents); api.use('/simcaq_first_report', simcaqFirstReport); api.use('/enrollment_diagnosis', enrollmentDiagnosis); +api.use('/simcaq_second_report', simcaqSecondReport); module.exports = api; diff --git a/src/libs/routes_v2/simcaqFirstReport.js b/src/libs/routes_v2/simcaqFirstReport.js index db300da53a36c308186aedc30def6a5cbecf2163..c4c4b9784733ce1cb2ab043bcbde91a7b09b1d51 100644 --- a/src/libs/routes_v2/simcaqFirstReport.js +++ b/src/libs/routes_v2/simcaqFirstReport.js @@ -127,6 +127,7 @@ simcaqFirstReportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('simcaq_relatorio_1.localizacao_id', 'location') .field('SUM(simcaq_relatorio_1.num_matriculas)', 'num_enrollments') .field('SUM(simcaq_relatorio_1.num_escolas)', 'num_schools') + .where('situacao_funcionamento_pareada = 1 AND (ensino_regular = 1 OR ensino_eja = 1 OR educacao_profissional = 1)') .group('simcaq_relatorio_1.etapa') .group('simcaq_relatorio_1.turno') .group('simcaq_relatorio_1.localizacao_id'); diff --git a/src/libs/routes_v2/simcaqSecondReport.js b/src/libs/routes_v2/simcaqSecondReport.js new file mode 100644 index 0000000000000000000000000000000000000000..51907e3308d8ee25a68e0259e8f827c8f426706e --- /dev/null +++ b/src/libs/routes_v2/simcaqSecondReport.js @@ -0,0 +1,110 @@ +/* +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 simcaqSecondReportApp = 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(); + +simcaqSecondReportApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addValue({ + name: 'year', + table: 'simcaq_relatorio_2', + tableField: 'ano_censo', + where : { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'school', + table: 'simcaq_relatorio_2', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).addValue({ + name: 'city', + table:'simcaq_relatorio_2', + tableField: 'municipio_id', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id' + } +}).addValue({ + name: 'adm_dependency', + table: 'simcaq_relatorio_2', + tableField: 'dependencia_adm_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}).addValue({ + name: 'state', + table: 'simcaq_relatorio_2', + tableField: 'estado_id', + where: { + relation: '=', + type: 'integer', + field: 'estado_id' + } +}); + +simcaqSecondReportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_relatorio_2') + .field('sum(num_matriculas_total)' ,'num_enrollments_total') + .field('sum(num_matriculas_rural)' ,'num_enrollments_rural') + .field('sum(num_matriculas_urbana)' ,'num_enrollments_urban') + .field('sum(num_escolas_total)' ,'num_schools_total') + .field('sum(num_escolas_rural)' ,'num_schools_rural') + .field('sum(num_escolas_urbana)' ,'num_schools_urban') + .field('dependencia_adm_priv', 'private_adm_dependency') + .where('situacao_funcionamento_pareada = 1 AND (ensino_regular = 1 OR ensino_eja = 1 OR educacao_profissional = 1)') + .group('dependencia_adm_priv') + next(); +}, query, response('simcaqSecondReport')); + +module.exports = simcaqSecondReportApp;