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

Start change in enrollment route to new db schema

parent 56abd94e
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!34Db simcaq dev2
Pipeline #
......@@ -19,16 +19,15 @@ let rqf = new ReqQueryFields();
// Complete range of the enrollments dataset.
// Returns a tuple of start and ending years of the complete enrollments dataset.
enrollmentApp.get('/year_range', (req, res, next) => {
req.sql.from('turma')
.field('MIN(turma.ano_censo)', 'start_year')
.field('MAX(turma.ano_censo)', 'end_year');
req.sql.from('matricula')
.field('MIN(matricula.ano_censo)', 'start_year')
.field('MAX(matricula.ano_censo)', 'end_year');
next();
}, query, response('range'));
enrollmentApp.get('/location', (req, res, next) => {
req.sql = squel.select()
.field('pk_localizacao_id', 'id')
.field('id')
.field('descricao', 'name')
.from('localizacao');
next();
......@@ -37,18 +36,16 @@ enrollmentApp.get('/location', (req, res, next) => {
// Returns all educational levels avaible
enrollmentApp.get('/education_level', (req, res, next) => {
req.sql.from('etapa_ensino')
.field('pk_etapa_ensino_id', 'id')
.field('id', 'id')
.field('desc_etapa', 'name');
next();
}, query, response('education_level'));
// Returns all adm dependencies
enrollmentApp.get('/adm_dependency', (req, res, next) => {
req.sql.from('dependencia_adm')
.field('pk_dependencia_adm_id', 'id')
.field('id', 'id')
.field('nome', 'name');
next();
}, query, response('adm_dependency'));
......@@ -68,12 +65,12 @@ rqf.addField({
where: {
relation: '=',
type: 'integer',
field: 'pk_dependencia_adm_id'
field: 'id'
},
join: {
primary: 'pk_dependencia_adm_id',
foreign: 'fk_dependencia_adm_id',
foreignTable: 'turma'
primary: 'id',
foreign: 'dependencia_adm_id',
foreignTable: 'matricula'
}
}).addValue({
name: 'education_level',
......@@ -83,12 +80,12 @@ rqf.addField({
where: {
relation: '=',
type: 'integer',
field: 'pk_etapa_ensino_id'
field: 'id'
},
join: {
primary: 'pk_etapa_ensino_id',
foreign: 'fk_etapa_ensino_id',
foreignTable: 'turma'
primary: 'id',
foreign: 'etapa_ensino_id',
foreignTable: 'matricula'
}
}).addValue({
name: 'region',
......@@ -98,12 +95,12 @@ rqf.addField({
where: {
relation: '=',
type: 'integer',
field: 'pk_regiao_id'
field: 'id'
},
join: {
primary: 'pk_regiao_id',
foreign: 'fk_regiao_id',
foreignTable: 'turma'
primary: 'id',
foreign: 'cod_regiao',
foreignTable: 'matricula'
}
}).addValue({
name: 'state',
......@@ -113,12 +110,12 @@ rqf.addField({
where: {
relation: '=',
type: 'integer',
field: 'pk_estado_id'
field: 'id'
},
join: {
primary: 'pk_estado_id',
foreign: 'fk_estado_id',
foreignTable: 'turma'
primary: 'id',
foreign: 'escola_estado_id',
foreignTable: 'matricula'
}
}).addValue({
name: 'city',
......@@ -128,12 +125,12 @@ rqf.addField({
where: {
relation: '=',
type: 'integer',
field: 'pk_cod_ibge'
field: 'id'
},
join: {
primary: 'pk_cod_ibge',
foreign: 'fk_municipio_id',
foreignTable: 'turma'
primary: 'id',
foreign: 'escola_municipio_id',
foreignTable: 'matricula'
}
}).addValue({
name: 'school',
......@@ -143,12 +140,12 @@ rqf.addField({
where: {
relation: '=',
type: 'integer',
field: 'cod_entidade'
field: 'id'
},
join: {
primary: 'cod_entidade',
foreign: 'cod_entidade',
foreignTable: 'turma'
primary: 'id',
foreign: 'escola_id',
foreignTable: 'matricula'
}
}).addValue({
name: 'location',
......@@ -158,31 +155,16 @@ rqf.addField({
where: {
relation: '=',
type: 'integer',
field: 'pk_localizacao_id'
},
join: {
primary: 'pk_localizacao_id',
foreign: 'fk_localizacao_id',
foreignTable: 'turma'
}
}).addValue({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'pk_cod_ibge'
field: 'id'
},
join: {
primary: 'pk_cod_ibge',
foreign: 'fk_municipio_id',
foreignTable: 'turma'
primary: 'id',
foreign: 'localizacao_id',
foreignTable: 'matricula'
}
}).addValue({
name: 'min_year',
table: 'turma',
table: 'matricula',
tableField: 'ano_censo',
resultField: 'year',
where: {
......@@ -192,7 +174,7 @@ rqf.addField({
}
}).addValue({
name: 'max_year',
table: 'turma',
table: 'matricula',
tableField: 'ano_censo',
resultField: 'year',
where: {
......@@ -204,12 +186,13 @@ rqf.addField({
enrollmentApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
log.debug(req.sql.toParam());
req.sql.field('COALESCE(SUM(num_matriculas), 0)', 'total')
req.sql.field('COALESCE(COUNT(matricula.id), 0)', 'total')
.field("'Brasil'", 'name')
.field('turma.ano_censo', 'year')
.from('turma')
.group('turma.ano_censo')
.order('turma.ano_censo');
.field('matricula.ano_censo', 'year')
.from('matricula')
.group('matricula.ano_censo')
.order('matricula.ano_censo')
.where('matricula.tipo=0 OR matricula.tipo=1 OR matricula.tipo=2 OR matricula.tipo=3');
next();
}, query, response('enrollment'));
......
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