Skip to content
Snippets Groups Projects
Commit 748a36c9 authored by Gabriel Ruschel's avatar Gabriel Ruschel
Browse files

Adapt classroom route and add subroutes

parent c0a65e0b
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!40Classroom route fix
......@@ -12,8 +12,44 @@ const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const id2str = require(`${libs}/middlewares/id2str`);
let rqf = new ReqQueryFields();
let rqfCount = new ReqQueryFields();
// Complete range of the enrollments dataset.
// Returns a tuple of start and ending years of the complete enrollments dataset.
classroomApp.get('/year_range', (req, res, next) => {
req.sql.from('escola')
.field('MIN(escola.ano_censo)', 'start_year')
.field('MAX(escola.ano_censo)', 'end_year');
next();
}, query, response('range'));
classroomApp.get('/adm_dependency', (req, res, next) => {
req.sql.from('dependencia_adm')
.field('id')
.field('nome', 'name')
.where('id <= 4');
next()
}, query, response('adm_dependency'));
classroomApp.get('/adm_dependency_detailed', (req, res, next) => {
req.sql.from('dependencia_adm')
.field('id', 'id')
.field('nome', 'name');
next()
}, query, response('adm_dependency_detailed'));
classroomApp.get('/location', (req, res, next) => {
req.sql = squel.select()
.field('id')
.field('descricao', 'name')
.from('localizacao');
next()
}, query, response('location'));
rqf.addField({
name: 'filter',
field: false,
......@@ -79,56 +115,54 @@ rqf.addField({
foreignTable: 'escola'
}
}).addValue({
name: 'year',
name: 'min_year',
table: 'escola',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '=',
relation: '>=',
type: 'integer',
field: 'ano_censo',
table: 'escola'
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'escola',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'adm_dependency',
table: 'dependencia_adm',
tableField: 'nome',
resultField: 'adm_dependency_name',
table: 'escola',
tableField: 'dependencia_adm_id',
resultField: 'adm_dependency_id',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'dependencia_adm_id',
foreignTable: 'escola'
field: 'dependencia_adm_id'
}
}).addValue({
name: 'adm_dependency_detailed',
table: 'dependencia_adm',
tableField: 'nome',
resultField: 'adm_dependency_detailed_name',
table: 'escola',
tableField: 'dependencia_adm_priv',
resultField: 'adm_dependency_detailed_id',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'dependencia_adm_priv',
foreignTable: 'escola'
field: 'dependencia_adm_priv'
}
}).addValue({
name: 'locality',
name: 'location',
table: 'escola',
tableField: 'cod_localizacao',
resultField: 'locality',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_localizacao',
table: 'escola'
field: 'cod_localizacao'
}
});
......@@ -142,6 +176,6 @@ classroomApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.order('escola.ano_censo')
.where('escola.situacao_de_funcionamento = 1 AND escola.local_func_predio_escolar = 1');
next();
}, query, response('classroom'));
}, query, id2str.transform(true), response('classroom'));
module.exports = classroomApp;
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