diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index 7fa6818b899bec190e320373e605b81b7aeb76a5..f6715eaa36c611eb5632d801cf3546ccd528fa16 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -118,6 +118,8 @@ const educationalBudget = require(`${libs}/routes/educationalBudget`); const schoolLocation = require(`${libs}/routes/schoolLocation`); +const studentsAee = require(`${libs}/routes/studentsAee`); + const mesoregion = require(`${libs}/routes/mesoregion`); const microregion = require(`${libs}/routes/microregion`); @@ -182,6 +184,7 @@ api.use('/university', university); api.use('/university_teacher', universityTeacher); api.use('/course_count', courseCount); api.use('/school_location', schoolLocation); +api.use('/students_aee', studentsAee); api.use('/mesoregion', mesoregion); api.use('/microregion', microregion); api.use('/location', location); diff --git a/src/libs/routes/city.js b/src/libs/routes/city.js index 1686c850aeea190dd8af43acf46acc9d0ceb8bb8..fc697a9f5d146c48c5e87c49ec54572566b22f82 100644 --- a/src/libs/routes/city.js +++ b/src/libs/routes/city.js @@ -69,6 +69,22 @@ rqf.addField({ foreign: 'estado_id', foreignTable: 'municipio' } +}).addValue({ + name: 'state_not', + table: 'estado', + tableField: ['nome', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '<>', + type: 'integer', + field: 'estado_id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'municipio' + } }).addField({ name: 'search', field: false, @@ -100,7 +116,23 @@ rqf.addField({ type: 'integer', field: 'microrregiao_id' } -}); +}).addValueToField({ + name: 'region', + table: 'estado', + tableField: 'regiao_id', + resultField: 'region_id', + where: { + relation: '=', + type: 'integer', + field: 'regiao_id', + table: 'estado' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'municipio' + } +}, 'filter'); // Return all cities cityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { diff --git a/src/libs/routes/region.js b/src/libs/routes/region.js index b1076e6484836b8a4911b8d0ada3631f1304e3c0..5df65e726e1895f256f276ce22a32b1c7cc41712 100644 --- a/src/libs/routes/region.js +++ b/src/libs/routes/region.js @@ -36,6 +36,16 @@ rqf.addField({ field: 'id', table: '@' } +}).addValue({ + name: 'id_not', + table: '@', + tableField: 'id', + where: { + relation: '<>', + type: 'integer', + field: 'id', + table: '@' + } }).addField({ name: 'search', field: false, diff --git a/src/libs/routes/state.js b/src/libs/routes/state.js index 453ca6ebbe30aa330fc1e8949cc8db4ae1bf7bb7..c9830b20a52b2997ab96f020c893a00e10d4c3df 100644 --- a/src/libs/routes/state.js +++ b/src/libs/routes/state.js @@ -53,6 +53,15 @@ rqf.addField({ type: 'integer', field: 'id' } +}).addValue({ + name: 'id_not', + table: 'estado', + tableField: 'id', + where: { + relation: '<>', + type: 'integer', + field: 'id' + } }).addValue({ name: 'region', table: 'regiao', diff --git a/src/libs/routes/studentsAee.js b/src/libs/routes/studentsAee.js new file mode 100644 index 0000000000000000000000000000000000000000..2a45a2f5f038407b2fe6b9dbb4b44c504ce4e77e --- /dev/null +++ b/src/libs/routes/studentsAee.js @@ -0,0 +1,219 @@ +const express = require('express'); + +const studentsAeeApp = 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 id2str = require(`${libs}/middlewares/id2str`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const request = require(`request`); + +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(); +let rqfCount = new ReqQueryFields(); + +// cubApp.get('/year_range', (req, res, next) => { + +// req.sql.from('cub') +// .field('MIN(cub.ano_censo)', 'start_year') +// .field('MAX(cub.ano_censo)', 'end_year'); +// next(); +// }, query, response('range')); + +// cubApp.get('/years', (req, res, next) => { +// req.sql.from('cub') +// .field('DISTINCT cub.ano_censo', 'year'); +// next(); +// }, query, response('years')); + +// cubApp.get('/months', (req, res, next) => { +// req.sql.from('cub') +// .field('DISTINCT cub.mes_censo', 'month'); +// next(); +// }, query, response('months')); + +// cubApp.get('/years_months', (req, res, next) => { +// req.sql.from('cub') +// .field('DISTINCT cub.ano_censo AS "year", cub.mes_censo AS "month"'); +// next(); +// }, query, response('years_months')); + +// cubApp.get('/price_type', (req, res, next) => { +// req.sql.from('cub') +// .field('DISTINCT cub.tipo_preco', 'price_type'); +// next(); +// }, query, response('price_type')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValueToField({ + name: 'state', // working + table: 'estado', + tableField: ['sigla', 'id'], + resultField: ['sigla_uf', 'cod_uf'], + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: 'numero_estudantes_aee' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'numero_estudantes_aee' + } +}, 'filter').addValueToField({ + name: 'city', // working + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'numero_estudantes_aee' + } +}, 'filter').addValue({ + name: 'region', // working + table: 'regiao', + tableField: ['nome', 'id'], + resultField: ['region_name', 'region_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'regiao_id', + foreignTable: 'numero_estudantes_aee' + } +}).addValueToField({ + name: 'school', // working + table: 'escola', + tableField: ['nome_escola', 'id'], + resultField: ['school_name', 'school_id'], + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: ['id', 'ano_censo'], + foreign: ['escola_id', 'ano_censo'], + foreignTable: 'numero_estudantes_aee' + } +}, 'filter').addValueToField({ + name: 'locale_id', // working + table: 'numero_estudantes_aee', + tableField: 'localidade_area_rural', + resultField: 'locale_id', + where: { + relation: '=', + type: 'integer', + field: 'localidade_area_rural' + } +}, 'filter').addValue({ + name: 'ethnic_group', // working + table: 'numero_estudantes_aee', + tableField: 'cor_raca_id', + resultField: 'ethnic_group_id', + where: { + relation: '=', + type: 'integer', + field: 'cor_raca_id' + } +}).addValue({ + name: 'adm_dependency', // working + table: 'numero_estudantes_aee', + tableField: 'dependencia_adm_priv', + resultField: 'adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_priv' + } +}).addValue({ + name:'age_range_all', // working + table: 'numero_estudantes_aee', + tableField: 'faixa_etaria_31_03', + resultField: 'age_range_all_id', + where: { + relation: '=', + type: 'integer', + field: 'faixa_etaria_31_03' + } + }).addValue({ + name: 'gender', // working + table: 'numero_estudantes_aee', + tableField: 'sexo', + resultField: 'gender_id', + where: { + relation: '=', + type: 'integer', + field: 'sexo' + } +}).addValue({ + name: 'activity_days', // working + table: 'numero_estudantes_aee', + tableField: 'dias_atividade', + resultField: 'activity_days_id', + where: { + relation: '=', + type: 'integer', + field: 'dias_atividade' + } +}).addField({ + name: 'special_service', // working + table: 'numero_estudantes_aee', + tableField: 'disc_atendimento_especiais', + resultField: 'special_service_id', + where: { + relation: '=', + type: 'integer', + field: 'disc_atendimento_especiais' + } +}); + +studentsAeeApp.get('/', rqf.parse(), (req, res, next) => { + req.sql.from('numero_estudantes_aee') + .field('numero_estudantes_aee.ano_censo') + .field('COUNT(distinct numero_estudantes_aee.id_aluno)', 'total') + .group('numero_estudantes_aee.ano_censo') + .order('numero_estudantes_aee.ano_censo') + next(); +}, rqf.build(), (req, res, next) => { + console.log(req.sql.toString()); + next(); +}, query, id2str.transform(), response('studentsAee')); + +module.exports = studentsAeeApp; diff --git a/src/libs/routes/universityEnrollment.js b/src/libs/routes/universityEnrollment.js index 7b40635c08ce529e90dd46e07c637fe2ed0f3d4c..3a1d6e4776004cbeaac79d95c622e694d3dd4e12 100644 --- a/src/libs/routes/universityEnrollment.js +++ b/src/libs/routes/universityEnrollment.js @@ -466,8 +466,8 @@ rqf.addField({ }).addValue({ name:'ocde_specific', table: '@', - tableField: ['par_cod_ocde_area_especifica', 'nome_ocde_area_especifica'], - resultField: ['ocde_specific_id', 'ocde_specific_name'], + tableField: ['par_cod_ocde_area_especifica'], + resultField: ['ocde_specific_id'], where: { relation: '=', type: 'integer', @@ -476,8 +476,8 @@ rqf.addField({ }).addValue({ name:'ocde_geral', table: '@', - tableField: ['par_cod_ocde_area_geral', 'nome_ocde_area_geral'], - resultField: ['ocde_geral_id', 'ocde_geral_name'], + tableField: ['par_cod_ocde_area_geral'], + resultField: ['ocde_geral_id'], where: { relation: '=', type: 'integer', @@ -486,8 +486,8 @@ rqf.addField({ }).addValue({ name:'ocde_detailed', table: '@', - tableField: ['par_cod_ocde_area_detalhada', 'nome_ocde_area_detalhada'], - resultField: ['ocde_detailed_id', 'ocde_detailed_name'], + tableField: ['par_cod_ocde_area_detalhada'], + resultField: ['ocde_detailed_id'], where: { relation: '=', type: 'integer', diff --git a/src/libs/routes/universityLocalOffer.js b/src/libs/routes/universityLocalOffer.js index 4a594f62d7c132dd875a7f334df8b5728905a25b..535094c492915b6b3d38a5e02a267a4196910c36 100644 --- a/src/libs/routes/universityLocalOffer.js +++ b/src/libs/routes/universityLocalOffer.js @@ -126,13 +126,38 @@ rqf.addField({ foreign: 'cod_uf', foreignTable: 'localoferta_ens_superior' } +}).addValueToField({ + name: 'university', + table: 'localoferta_ens_superior', + tableField: 'cod_ies', + resultField: 'university_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_ies', + table: 'localoferta_ens_superior' + } +}, 'filter').addValue({ + name: 'year', + table: 'localoferta_ens_superior', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '=', + type: 'integer', + table: 'localoferta_ens_superior', + field: 'ano_censo' + } }); + universityLocalOfferApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.sql.from('localoferta_ens_superior') .field('distinct localoferta_ens_superior.cod_ies', 'id') + .field('localoferta_ens_superior.cod_local_oferta', 'localoffer_id') .field('localoferta_ens_superior.ano_censo', 'year') .field('ies_ens_superior.nome_ies', 'name') + .field('localoferta_ens_superior.nome', 'localoffer_name') .field('localoferta_ens_superior.cod_uf', 'state_id') .field('localoferta_ens_superior.cod_municipio', 'city_id') .field('localoferta_ens_superior.cod_regiao', 'region_id')