Skip to content
Snippets Groups Projects
Commit 0f6c1ecd authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Fix bug in the field ano_censo

parent 5b583b02
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!106Gloss enrollment ratio route
Pipeline #
......@@ -24,6 +24,8 @@ const download = require(`${libs}/middlewares/downloadDatabase`);
const passport = require('passport');
const addMissing = require(`${libs}/middlewares/addMissing`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
glossEnrollmentRatioApp.use(cache('15 day'));
......@@ -37,13 +39,38 @@ glossEnrollmentRatioApp.get('/year_range', (req, res, next) => {
.field('MIN(pnad.ano_censo)', 'start_year')
.field('MAX(pnad.ano_censo)', 'end_year');
next();
}, query, (req, res, next) => {
req.sql.from('matricula')
.field('MIN(matricula.ano_censo)', 'start_year')
.field('MAX(matricula.ano_censo)', 'end_year');
req.old_result = req.result;
next();
}, query, (req, res, next) => {
if (req.old_result[0].start_year < req.result[0].start_year) {
req.result[0].start_year = req.old_result[0].start_year;
}
if (req.old_result[0].end_year > req.result[0].end_year) {
req.result[0].end_year = req.old_result[0].old_result;
}
next();
}, query, response('range'));
glossEnrollmentRatioApp.get('/years', (req, res, next) => {
req.sql.from('matricula')
.field('DISTINCT matricula.ano_censo', 'year');
next();
}, query, (req, res, next) => {
req.oldResult = req.result;
req.sql = squel.select();
req.sql.from('pnad')
.field('DISTINCT pnad.ano_censo', 'year');
next();
}, query, response('years'));
}, query, (req, res, next) => {
let result = Object.assign(req.oldResult, req.result);
req.result = result;
next();
}, response('years'));
glossEnrollmentRatioApp.get('/source', (req, res, next) => {
req.sql.from('fonte')
......@@ -163,24 +190,24 @@ rqf.addField({
}
}).addValue({
name: 'min_year',
table: 'pnad',
table: '@',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
table: 'pnad',
table: '@',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'pnad',
table: '@',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
table: 'pnad',
table: '@',
field: 'ano_censo'
}
}).addValue({
......@@ -300,8 +327,8 @@ glossEnrollmentRatioApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
let m_k = req.sql.clone();
log.debug(m_k);
m_k.field('sum(matricula.etapa_resumida)', 'total')
.from('matricula')
m_k.from('matricula')
.field('sum(matricula.etapa_resumida)', 'total')
.field('matricula.ano_censo', 'year')
.group('matricula.ano_censo')
.order('matricula.ano_censo')
......
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