Newer
Older
const express = require('express');
const teacherApp = express.Router();
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const squel = require('squel');
const query = require(`${libs}/middlewares/query`);
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const id2str = require(`${libs}/middlewares/id2str`);
let rqf = new ReqQueryFields();
// Returns a tuple of start and ending years of the complete enrollments dataset.
teacherApp.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'));
teacherApp.get('/years', (req, res, next) => {
req.sql.from('docente').
field('DISTINCT docente.ano_censo', 'years');
next();
}, query, response('years'));
teacherApp.get('/adm_dependency_detailed', (req, res, next) => {
req.sql.from('dependencia_adm')
.field('id', 'id')
.field('nome', 'name');
next();
}, query, response('adm_dependency_detailed'));
teacherApp.get('/adm_dependency', (req, res, next) => {
req.sql.from('dependencia_adm')
.field('id')
.field('nome', 'name')
.where('id <= 4');
next();
}, query, response('adm_dependency'));
teacherApp.get('/education_level_mod', (req, res, next) => {
req.sql.from('etapas_mod_ensino_segmento')
.field('id')
.field('nome', 'name');
next();
}, query, response('education_level_mod'));
teacherApp.get('/education_level_short', (req, res, next) => {
req.result = [
{id: null, name: 'Não Classificado'},
{id: 1, name: 'Creche'},
{id: 2, name: 'Pré-Escola'},
{id: 3, name: 'Ensino Fundamental - anos iniciais'},
{id: 4, name: 'Ensino Fundamental - anos finais'},
{id: 5, name: 'Ensino Médio'},
{id: 6, name: 'EJA'},
{id: 7, name: 'EE exclusiva'}
];
next();
}, response('education_level_short'));
teacherApp.get('/location', (req, res, next) => {
req.sql.from('localizacao')
.field('id')
.field('descricao', 'name')
.where('id <= 2');
next();
}, query, response('location'));
teacherApp.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'));
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
teacherApp.get('/education_type', (req, res, next) => {
req.sql.from('docente')
.field('DISTINCT nivel_tipo_formacao', 'id')
.order('id');
next();
}, query, (req, res, next) => {
req.result.forEach((result) => {
result.name = id2str.educationType(result.id);
});
next();
}, response('education_type'));
teacherApp.get('/gender', (req, res, next) => {
req.result = [
{id: 1, name: 'Masculino'},
{id: 2, name: 'Feminino'}
];
next();
}, response('gender'));
teacherApp.get('/ethnic_group', (req, res, next) => {
req.sql.from('cor_raca')
.field('id')
.field('nome', 'name');
next();
}, query, 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: 'education_level_short',
table: 'docente',
tableField: 'etapa_resumida',
resultField: 'education_level_short_id',
where: {
relation: '=',
type: 'integer',
field: 'etapa_resumida'
}
}).addValue({
name: 'education_type',
table: 'docente',
tableField: 'nivel_tipo_formacao',
resultField: 'education_type_id',
where: {
relation: '=',
type: 'integer',
field: 'nivel_tipo_formacao'
}
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
}).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'
}
}).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'
}
name: 'school',
table: 'escola',
tableField: 'nome_escola',
resultField: 'school_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: ['id', 'ano_censo'],
foreign: ['escola_id', 'ano_censo'],
foreignTable: 'docente'
}
}).addValue({
name: 'location',
table: 'docente',
tableField: 'cod_localizacao',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_localizacao'
}
}).addValue({
name: 'rural_location',
table: 'docente',
tableField: 'localidade_area_rural',
resultField: 'rural_location_id',
where: {
relation: '=',
type: 'integer',
field: 'localidade_area_rural'
}
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
}).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: '=',
}
});
teacherApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.sql.field('COUNT(DISTINCT docente.id)', 'total')
.field("'Brasil'", 'name')
.field('docente.ano_censo', 'year')
.from('docente')
.join('turma', null, 'docente.turma_id=turma.id AND docente.ano_censo=turma.ano_censo')
.group('docente.ano_censo')
.order('docente.ano_censo')
.where('(docente.tipo_docente = 1 OR docente.tipo_docente = 5) AND (turma.tipo_turma_id <= 3)');
next();