diff --git a/src/libs/routes_v2/api.js b/src/libs/routes_v2/api.js index 906af9cf686b1360d07ecc7f84ab58fdf25b1c74..5365e80e733fc3781a4cb8dd77c9db14d70d67db 100644 --- a/src/libs/routes_v2/api.js +++ b/src/libs/routes_v2/api.js @@ -134,6 +134,8 @@ const message = require(`${libs}/routes_v2/message`); const courseStudents = require(`${libs}/routes_v2/courseStudents`); +const simcaqFirstReport = require(`${libs}/routes_v2/simcaqFirstReport`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v2 is running' }); }); @@ -192,5 +194,6 @@ api.use('/disciplines', disciplines); api.use('/universityLocalOffer', universityLocalOffer); api.use('/message', message); api.use('/course_students', courseStudents); +api.use('/simcaq_first_report', simcaqFirstReport); module.exports = api; diff --git a/src/libs/routes_v2/simcaqFirstReport.js b/src/libs/routes_v2/simcaqFirstReport.js new file mode 100644 index 0000000000000000000000000000000000000000..db300da53a36c308186aedc30def6a5cbecf2163 --- /dev/null +++ b/src/libs/routes_v2/simcaqFirstReport.js @@ -0,0 +1,136 @@ +/* +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 simcaqFirstReportApp = 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(); + +simcaqFirstReportApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addValue({ + name: 'year', + table: 'simcaq_relatorio_1', + tableField: 'ano_censo', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'adm_dependency', + table: 'simcaq_relatorio_1', + tableField: 'dependencia_adm_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}).addValue({ + name: 'city', + table: 'simcaq_relatorio_1', + tableField: 'municipio_id', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id' + } +}).addValue({ + name: 'state', + table: 'simcaq_relatorio_1', + tableField: 'estado_id', + where: { + relation: '=', + type: 'integer', + field: 'estado_id' + } +}).addValue({ + name: 'school', + table: 'simcaq_relatorio_1', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).addValue({ + name: 'location', + table: 'simcaq_relatorio_1', + tableField: 'localizacao_id', + where: { + relation: '=', + type: 'integer', + field: 'localizacao_id' + } +}).addValue({ + name: 'stage', + table: 'simcaq_relatorio_1', + tableField: 'etapa', + where: { + relation: '=', + type: 'integer', + field: 'etapa' + } +}).addValue({ + name: 'shift', + table: 'simcaq_relatorio_1', + tableField: 'turno', + where: { + relation: '=', + type: 'integer', + field: 'turno' + } +}); + +simcaqFirstReportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_relatorio_1') + .field('simcaq_relatorio_1.etapa', 'stage') + .field('simcaq_relatorio_1.turno', 'shift') + .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') + .group('simcaq_relatorio_1.etapa') + .group('simcaq_relatorio_1.turno') + .group('simcaq_relatorio_1.localizacao_id'); + next(); +}, query, response('simcaqFirstReport')); + +module.exports = simcaqFirstReportApp;