Skip to content
Snippets Groups Projects
Commit 7063e290 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Merge branch 'auxiliar-indicator' into release_v1.4.0

Conflicts:
* CHANGELOG.md
* src/libs/routes/api.js
* src/libs/routes/transport.js
parents 9afe6816 ae757004
No related branches found
No related tags found
1 merge request!133Release v1.4.0
Pipeline #16347 canceled
...@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ...@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed ### Changed
- Fixed CSV output when result objects have nested arrays and/or objects - Fixed CSV output when result objects have nested arrays and/or objects
- Limit year range to 2007-2015 in out of school indicator - Limit year range to 2007-2015 in out of school indicator
- Fix auxiliar indicator
## 1.3.3 - 2018-06-27 ## 1.3.3 - 2018-06-27
### Changed ### Changed
......
...@@ -66,6 +66,8 @@ const classroomCount = require(`${libs}/routes/classroomCount`); ...@@ -66,6 +66,8 @@ const classroomCount = require(`${libs}/routes/classroomCount`);
const transport = require(`./transport`); const transport = require(`./transport`);
const auxiliar = require(`${libs}/routes/auxiliar`);
const dailyChargeAmount = require(`${libs}/routes/dailyChargeAmount`); const dailyChargeAmount = require(`${libs}/routes/dailyChargeAmount`);
const cub = require(`${libs}/routes/cub`); const cub = require(`${libs}/routes/cub`);
...@@ -107,5 +109,6 @@ api.use('/classroom_count', classroomCount); ...@@ -107,5 +109,6 @@ api.use('/classroom_count', classroomCount);
api.use('/daily_charge_amount', dailyChargeAmount); api.use('/daily_charge_amount', dailyChargeAmount);
api.use('/transport', transport); api.use('/transport', transport);
api.use('/cub', cub); api.use('/cub', cub);
api.use('/auxiliar', auxiliar);
module.exports = api; module.exports = api;
const express = require('express');
const auxiliarApp = express.Router();
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const squel = require('squel');
const query = require(`${libs}/middlewares/query`).query;
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const id2str = require(`${libs}/middlewares/id2str`);
const config = require(`${libs}/config`);
const passport = require('passport');
const download = require(`${libs}/middlewares/downloadDatabase`);
const addMissing = require(`${libs}/middlewares/addMissing`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
let rqf = new ReqQueryFields();
auxiliarApp.use(cache('15 day'));
auxiliarApp.get('/year_range', (req, res, next) => {
req.sql.from('docente')
.field('MIN(docente.ano_censo)', 'start_year')
.field('MAX(docente.ano_censo)', 'end_year');
next();
}, query, response('range'));
auxiliarApp.get('/years', (req, res, next) => {
req.sql.from('docente').
field('DISTINCT docente.ano_censo', 'year');
next();
}, query, response('years'));
auxiliarApp.get('/source', (req, res, next) => {
req.sql.from('fonte')
.field('fonte', 'source')
.where('tabela = \'docente\'');
next();
}, query, response('source'))
auxiliarApp.get('/adm_dependency_detailed', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 6; ++i) {
req.result.push({
id: i,
name: id2str.admDependencyPriv(i)
});
};
next();
}, response('adm_dependency_detailed'));
auxiliarApp.get('/adm_dependency', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 4; ++i) {
req.result.push({
id: i,
name: id2str.admDependency(i)
});
};
next();
}, response('adm_dependency'));
auxiliarApp.get('/location', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 2; ++i) {
req.result.push({
id: i,
name: id2str.location(i)
});
};
next();
}, response('location'));
auxiliarApp.get('/rural_location', (req, res, next) => {
req.result = [
{id: 1, name: "Urbana"},
{id: 2, name: "Rural"},
{id: 3, name: "Rural - Área de assentamento"},
{id: 4, name: "Rural - Terra indígena"},
{id: 5, name: "Rural - Área remanescente de quilombos"},
{id: 6, name: "Rural - Unidade de uso sustentável"}
];
next();
}, response('rural_location'));
auxiliarApp.get('/education_level_mod', (req, res, next) => {
req.result = [];
for(let i = 1; i <= 11; ++i) {
req.result.push({
id: i,
name: id2str.educationLevelMod(i)
});
}
req.result.push({
id: 99,
name: id2str.educationLevelMod(99)
});
next();
}, response('education_level_mod'));
auxiliarApp.get('/gender', (req, res, next) => {
req.result = [
{id: 1, name: 'Masculino'},
{id: 2, name: 'Feminino'}
];
next();
}, response('gender'));
auxiliarApp.get('/ethnic_group', (req, res, next) => {
req.result = [];
for(let i = 0; i <=5; ++i) {
req.result.push({
id: i,
name: id2str.ethnicGroup(i)
});
}
next();
}, response('ethnic_group'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'adm_dependency',
table: 'docente',
tableField: 'dependencia_adm_id',
resultField: 'adm_dependency_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm_id'
}
}).addValue({
name: 'adm_dependency_detailed',
table: 'docente',
tableField: 'dependencia_adm_priv',
resultField: 'adm_dependency_detailed_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm_priv'
}
}).addValue({
name: 'education_level_mod',
table: 'docente',
tableField: 'etapas_mod_ensino_segmento_id',
resultField: 'education_level_mod_id',
where: {
relation: '=',
type: 'integer',
field: 'etapas_mod_ensino_segmento_id'
}
}).addValue({
name: 'region',
table: 'regiao',
tableField: 'nome',
resultField: 'region_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'escola_regiao_id',
foreignTable: 'docente'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'escola_estado_id',
foreignTable: 'docente'
}
}).addValue({
name: 'rural_location',
table: 'docente',
tableField: 'localidade_area_rural',
resultField: 'rural_location_id',
where: {
relation: '=',
type: 'integer',
field: 'localidade_area_rural'
}
}).addValueToField({
name: 'city',
table: 'municipio',
tableField: ['nome', 'id'],
resultField: ['city_name', 'city_id'],
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'escola_municipio_id',
foreignTable: 'docente'
}
}, 'dims').addValueToField({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'escola_municipio_id',
foreignTable: 'docente'
}
}, 'filter').addValue({
name: 'location',
table: 'docente',
tableField: 'cod_localizacao',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_localizacao'
}
}).addValue({
name: 'min_year',
table: 'docente',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'docente',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'gender',
table: 'docente',
tableField: 'sexo',
resultField: 'gender_id',
where: {
relation: '=',
type: 'integer',
field: 'sexo'
}
}).addValue({
name: 'ethnic_group',
table: 'docente',
tableField: 'cor_raca',
resultField: 'ethnic_group_id',
where: {
relation: '=',
type: 'integer',
field: 'cor_raca'
}
});
// LDE
auxiliarApp.get('/', rqf.parse(), (req, res, next) => {
req.sql.field('COUNT(DISTINCT docente.id)', 'total')
.field("'Brasil'", 'name')
.field('docente.ano_censo', 'year')
.from('docente')
.group('docente.ano_censo')
.order('docente.ano_censo')
.where('(docente.tipo_turma_id <= 3 AND docente.dependencia_adm_id > 1 AND docente.tipo_docente = 2)');
next();
}, rqf.build(), query, addMissing(rqf), id2str.transform(), response('auxiliar'));
// SimCAQ
auxiliarApp.get('/count', rqf.parse(), (req, res, next) => {
req.sql.field('COUNT(DISTINCT docente.id)', 'total')
.field("'Brasil'", 'name')
.field('docente.ano_censo', 'year')
.from('docente')
.group('docente.ano_censo')
.order('docente.ano_censo')
.where('((docente.tipo_turma_id <= 3) AND (docente.dependencia_adm_id = 2 OR docente.dependencia_adm_id = 3) AND (docente.tipo_docente = 2))');
next();
}, rqf.build(), query, addMissing(rqf), id2str.transform(), response('auxiliar'));
auxiliarApp.get('/download', passport.authenticate('bearer', { session: false }), rqf.parse(), rqf.build(), download('docente', 'mapping_docente'));
module.exports = auxiliarApp;
...@@ -348,6 +348,17 @@ transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { ...@@ -348,6 +348,17 @@ transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.where('matricula.tipo <= 3'); .where('matricula.tipo <= 3');
req.queryIndex.allEnrollment = req.querySet.push(allEnrollment) - 1; req.queryIndex.allEnrollment = req.querySet.push(allEnrollment) - 1;
let allEnrollmentTransport = req.sql.clone()
allEnrollmentTransport.field('COUNT(*)', 'total')
.field("'Brasil'", 'name')
.field('matricula.ano_censo', 'year')
.field('matricula.transporte_escolar_publico', 'use_transport_id')
.from('matricula')
.group('matricula.ano_censo')
.order('matricula.ano_censo')
.where('matricula.tipo <= 3');
req.queryIndex.allEnrollmentTransport = req.querySet.push(allEnrollmentTransport) - 1;
let allEnrollmentTransport = req.sql.clone() let allEnrollmentTransport = req.sql.clone()
allEnrollmentTransport.field('COUNT(*)', 'total') allEnrollmentTransport.field('COUNT(*)', 'total')
.field("'Brasil'", 'name') .field("'Brasil'", 'name')
......
process.env.NODE_ENV = 'test';
const chai = require('chai');
const dirtyChai = require('dirty-chai');
chai.use(dirtyChai);
const chaiXml = require('chai-xml');
chai.use(chaiXml);
const chaiHttp = require('chai-http');
const assert = chai.assert;
const expect = chai.expect;
const should = chai.should(); // actually call the function
const libs = `${process.cwd()}/libs`;
const server = require(`${libs}/app`);
chai.use(chaiHttp);
describe('request auxiliar', () => {
it('should list the year range', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/year_range')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('start_year');
res.body.result[0].should.have.property('end_year');
done();
});
});
it('should list the source', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/source')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('source');
done();
});
});
it('should list the locations', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/location')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('id');
res.body.result[0].should.have.property('name');
done();
});
});
it('should list the years', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/years')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('year');
done();
});
});
it('should list the rural locations', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/rural_location')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('id');
res.body.result[0].should.have.property('name');
done();
});
});
it('should list the education level mod', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/education_level_mod')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('id');
res.body.result[0].should.have.property('name');
done();
});
});
it('should list the administrative dependencies', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/adm_dependency')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('id');
res.body.result[0].should.have.property('name');
done();
});
});
it('should list the administrative dependencies detailed', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/adm_dependency_detailed')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('id');
res.body.result[0].should.have.property('name');
done();
});
});
it('should list genders', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/gender')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('id');
res.body.result[0].should.have.property('name');
done();
});
});
it('should list the ethnic groups', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/ethnic_group')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('id');
res.body.result[0].should.have.property('name');
done();
});
});
it('should list teachers count', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('name');
res.body.result[0].should.have.property('total');
done();
});
});
it('should list teacher count with valid filters', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?filter=min_year:2015,max_year:2015,state:41')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('name');
res.body.result[0].should.have.property('total');
done();
});
});
it('should list teacher count with invalid filters', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?filter=foo:2010,bar:41,min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('name');
res.body.result[0].should.have.property('total');
done();
});
});
it('should list teacher count with valid dimensions', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=region,state,adm_dependency,location,gender,ethnic_group&filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('region_name');
res.body.result[0].should.have.property('state_name');
res.body.result[0].should.have.property('adm_dependency_name');
res.body.result[0].should.have.property('location_name');
res.body.result[0].should.have.property('total');
done();
});
});
it('should list teacher count with invalid dimensions', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=foo,bar&filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('name');
res.body.result[0].should.have.property('total');
done();
});
});
it('should list teacher count with valid dimensions and filters', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=region,state,gender&filter=min_year:2015,max_year:2015,city:4106902')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('region_name');
res.body.result[0].should.have.property('state_name');
res.body.result[0].should.have.property('total');
res.body.result[0].should.have.property('year');
done();
});
});
it('should list teacher count with dimension location', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=location&filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('location_name');
done();
});
});
it('should list teacher count with dimension rural_location', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=rural_location&filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('rural_location_name');
done();
});
});
it('should list teacher count with dimension education_level_mod', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=education_level_mod&filter=min_year:2015,max_year:2015')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('education_level_mod_name');
done();
});
});
it('should list teacher count with dimension adm_dependency', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=adm_dependency&filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('adm_dependency_name');
done();
});
});
it('should list teacher count with dimension adm_dependency_detailed', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=adm_dependency_detailed&filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('adm_dependency_detailed_name');
done();
});
});
it('should list teacher count with dimension gender', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=gender&filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('gender_name');
done();
});
});
it('should list teacher count with dimension ethnic_group', (done) => {
chai.request(server)
.get('/api/v1/auxiliar/count?dims=ethnic_group&filter=min_year:2016,max_year:2016')
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('ethnic_group_name');
done();
});
});
});
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