Skip to content
Snippets Groups Projects
Commit 48b986dc authored by Leon A. Okida Gonçalves's avatar Leon A. Okida Gonçalves Committed by Pietro Cavassin
Browse files

Create first report route

parent 3664e40d
No related branches found
No related tags found
4 merge requests!377prd_version of simcaq,!368update filter in v2 school,!352V2 aggregated routes,!348Merge branch development into homologa
...@@ -134,6 +134,8 @@ const message = require(`${libs}/routes_v2/message`); ...@@ -134,6 +134,8 @@ const message = require(`${libs}/routes_v2/message`);
const courseStudents = require(`${libs}/routes_v2/courseStudents`); const courseStudents = require(`${libs}/routes_v2/courseStudents`);
const simcaqFirstReport = require(`${libs}/routes_v2/simcaqFirstReport`);
api.get('/', (req, res) => { api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API v2 is running' }); res.json({ msg: 'SimCAQ API v2 is running' });
}); });
...@@ -192,5 +194,6 @@ api.use('/disciplines', disciplines); ...@@ -192,5 +194,6 @@ api.use('/disciplines', disciplines);
api.use('/universityLocalOffer', universityLocalOffer); api.use('/universityLocalOffer', universityLocalOffer);
api.use('/message', message); api.use('/message', message);
api.use('/course_students', courseStudents); api.use('/course_students', courseStudents);
api.use('/simcaq_first_report', simcaqFirstReport);
module.exports = api; module.exports = api;
/*
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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment