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

Add teacher route

parent 6202ddb3
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!50Feature teacher route
Pipeline #
module.exports = function educationType(id) {
switch (id) {
case 1:
return 'Ensino Fundamental';
case 2:
return 'Ensino Médio';
case 3:
return 'Médio Normal ou Magistério';
case 4:
return 'Superior';
case 5:
return 'Superior com licenciatura';
case 6:
return 'Especialização';
case 7:
return 'Mestrado ou Doutorado';
default:
return 'Não definido';
}
};
...@@ -8,6 +8,7 @@ const ethnicGroup = require(`${libs}/convert/ethnicGroup`); ...@@ -8,6 +8,7 @@ const ethnicGroup = require(`${libs}/convert/ethnicGroup`);
const booleanVariable = require(`${libs}/convert/booleanVariable`); const booleanVariable = require(`${libs}/convert/booleanVariable`);
const educationLevel = require(`${libs}/convert/educationLevel`); const educationLevel = require(`${libs}/convert/educationLevel`);
const educationLevelMod = require(`${libs}/convert/educationLevelMod`); const educationLevelMod = require(`${libs}/convert/educationLevelMod`);
const educationType = require(`${libs}/convert/educationType`);
const ids = { const ids = {
gender_id: gender, gender_id: gender,
...@@ -19,7 +20,8 @@ const ids = { ...@@ -19,7 +20,8 @@ const ids = {
adm_dependency_detailed_id: admDependency, adm_dependency_detailed_id: admDependency,
location_id: location, location_id: location,
ethnic_group_id: ethnicGroup, ethnic_group_id: ethnicGroup,
integral_time_id: booleanVariable integral_time_id: booleanVariable,
education_type_id: educationType
}; };
function transform(removeId=false) { function transform(removeId=false) {
...@@ -48,5 +50,6 @@ module.exports = { ...@@ -48,5 +50,6 @@ module.exports = {
ethnicGroup, ethnicGroup,
booleanVariable, booleanVariable,
educationLevel, educationLevel,
educationLevelMod educationLevelMod,
educationType
}; };
...@@ -28,6 +28,8 @@ const user = require('./user'); ...@@ -28,6 +28,8 @@ const user = require('./user');
const classroom = require('./classroom'); const classroom = require('./classroom');
const teacher = require('./teacher');
api.get('/', (req, res) => { api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API is running' }); res.json({ msg: 'SimCAQ API is running' });
}); });
...@@ -43,5 +45,6 @@ api.use('/city', cache('15 day'), city); ...@@ -43,5 +45,6 @@ api.use('/city', cache('15 day'), city);
api.use('/school', cache('15 day'), school); api.use('/school', cache('15 day'), school);
api.use('/spatial', cache('1 day'), spatial); api.use('/spatial', cache('1 day'), spatial);
api.use('/classroom', cache('15 day'), classroom); api.use('/classroom', cache('15 day'), classroom);
api.use('/teacher', cache('1 day'), teacher);
module.exports = api; module.exports = api;
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('/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('/location', (req, res, next) => {
req.sql.from('localizacao')
.field('id')
.field('descricao', 'name')
.where('id <= 2');
next();
}, query, response('location'));
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_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: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'escola_municipio_id',
foreignTable: 'docente'
}
}).addValue({
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: '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'
}
});
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')
.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();
}, query, id2str.transform(true), response('teacher'));
module.exports = teacherApp;
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