diff --git a/src/libs/convert/admDependency.js b/src/libs/convert/admDependency.js new file mode 100644 index 0000000000000000000000000000000000000000..648fe41621adb5c436b346fd84d9e2c691ff25a9 --- /dev/null +++ b/src/libs/convert/admDependency.js @@ -0,0 +1,20 @@ +module.exports = function admDependency(id) { + switch (id) { + case 1: + return 'Federal'; + case 2: + return 'Estadual'; + case 3: + return 'Municipal'; + case 4: + return 'Privada'; + case 5: + return 'Privada conveniada'; + case 6: + return 'Privada não conveniada sem fins lucrativos'; + case 7: + return 'Privada não conveniada com fins lucrativos'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/ethnicGroup.js b/src/libs/convert/ethnicGroup.js new file mode 100644 index 0000000000000000000000000000000000000000..dfa51c810879cdd3655b73939766c2eae29333dd --- /dev/null +++ b/src/libs/convert/ethnicGroup.js @@ -0,0 +1,18 @@ +module.exports = function ethnicGroup(id) { + switch (id) { + case 0: + return 'Não declarada'; + case 1: + return 'Branca'; + case 2: + return 'Preta'; + case 3: + return 'Parda'; + case 4: + return 'Amarela'; + case 5: + return 'IndÃgena'; + default: + return 'Não declarada'; + } +}; diff --git a/src/libs/convert/gender.js b/src/libs/convert/gender.js new file mode 100644 index 0000000000000000000000000000000000000000..085eb20e0aa7fa18c2e9c3106fc6c8869b0bd639 --- /dev/null +++ b/src/libs/convert/gender.js @@ -0,0 +1,8 @@ +module.exports = function gender(id) { + switch(id) { + case 1: + return 'Masculino'; + case 2: + return 'Feminino'; + } +}; diff --git a/src/libs/convert/location.js b/src/libs/convert/location.js new file mode 100644 index 0000000000000000000000000000000000000000..606e06fc46a87bc5f1d1bf9c61aa8ad5ad06a353 --- /dev/null +++ b/src/libs/convert/location.js @@ -0,0 +1,16 @@ +module.exports = function location(id) { + switch (id) { + case 1: + return 'Urbana'; + case 2: + return 'Rural'; + case 3: + return 'Ãrea de assentamento'; + case 4: + return 'Terra indÃgena'; + case 5: + return 'Ãrea remanescente de quilombos'; + case 6: + return 'Unidade de uso sustentável'; + } +}; diff --git a/src/libs/convert/period.js b/src/libs/convert/period.js new file mode 100644 index 0000000000000000000000000000000000000000..d4b97b245fc740333f9e97eb19079648d9665dac --- /dev/null +++ b/src/libs/convert/period.js @@ -0,0 +1,12 @@ +module.exports = function period(id) { + switch(id) { + case 1: + return 'Diurno'; + case 2: + return 'Noturno'; + case 3: + return 'Integral'; + default: + return 'Indefinido'; + } +}; diff --git a/src/libs/convert/schoolYear.js b/src/libs/convert/schoolYear.js new file mode 100644 index 0000000000000000000000000000000000000000..485364c86fef34df51eeaf050870d4e2e38f0202 --- /dev/null +++ b/src/libs/convert/schoolYear.js @@ -0,0 +1,54 @@ +module.exports = function schoolYear(id) { + switch(id) { + case 11: + return 'Creche - Menor de 1 ano'; + case 12: + return 'Creche - 1 ano'; + case 13: + return 'Creche - 2 anos'; + case 14: + return 'Creche - 3 anos'; + case 21: + return 'Pré-escola - 4 anos'; + case 22: + return 'Pré-escola - 5 anos'; + case 31: + return 'Ens. Fundamental - 1º Ano'; + case 32: + return 'Ens. Fundamental - 1ª série/2º ano'; + case 33: + return 'Ens. Fundamental - 2ª série/3º ano'; + case 34: + return 'Ens. Fundamental - 3ª série/4º ano'; + case 35: + return 'Ens. Fundamental - 4ª série/5º Ano'; + case 41: + return 'Ens. Fundamental - 5ª série/6º ano'; + case 42: + return 'Ens. Fundamental - 6ª série/7º ano'; + case 43: + return 'Ens. Fundamental - 7ª série/8º ano'; + case 44: + return 'Ens. Fundamental - 8ª serie/9º ano'; + case 51: + return 'Ens. Médio - 1ª série'; // equivalent to 'EM 1 Série' + case 52: + return 'Ens. Médio - 2ª série'; // equivalent to 'EM 2 Série' + case 53: + return 'Ens. Médio - 3ª série'; // equivalent to 'EM 3 Série' + case 54: + return 'Ens. Médio - 4ª série'; // equivalent to 'EM 4 Série' + case 61: + return 'EJA - anos iniciais do Ens. Fundamental'; + case 62: + return 'EJA - anos finais do Ens. Fundamental'; + case 63: + return 'EJA - Ensino Médio'; + case 64: + return 'EJA semi-presencial'; + case 71: + return 'Educação Profissional'; + default: + return 'Não classificado'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 9d2eaa272b2fafe709304be3afb170da36b5789f..48ecf56cb759090b24b5c013997df80c6a1dfc41 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -1,84 +1,20 @@ -function gender(id) { - switch(id) { - case 1: - return 'Masculino'; - case 2: - return 'Feminino'; - } -} - -function period(id) { - switch(id) { - case 1: - return 'Diurno'; - case 2: - return 'Noturno'; - case 3: - return 'Integral'; - default: - return 'Indefinido'; - } -} - -function schoolYear(id) { - switch(id) { - case 11: - return 'Creche - Menor de 1 ano'; - case 12: - return 'Creche - 1 ano'; - case 13: - return 'Creche - 2 anos'; - case 14: - return 'Creche - 3 anos'; - case 21: - return 'Pré-escola - 4 anos'; - case 22: - return 'Pré-escola - 5 anos'; - case 31: - return 'Ens. Fundamental - 1º Ano'; - case 32: - return 'Ens. Fundamental - 1ª série/2º ano'; - case 33: - return 'Ens. Fundamental - 2ª série/3º ano'; - case 34: - return 'Ens. Fundamental - 3ª série/4º ano'; - case 35: - return 'Ens. Fundamental - 4ª série/5º Ano'; - case 41: - return 'Ens. Fundamental - 5ª série/6º ano'; - case 42: - return 'Ens. Fundamental - 6ª série/7º ano'; - case 43: - return 'Ens. Fundamental - 7ª série/8º ano'; - case 44: - return 'Ens. Fundamental - 8ª serie/9º ano'; - case 51: - return 'Ens. Médio - 1ª série'; // equivalent to 'EM 1 Série' - case 52: - return 'Ens. Médio - 2ª série'; // equivalent to 'EM 2 Série' - case 53: - return 'Ens. Médio - 3ª série'; // equivalent to 'EM 3 Série' - case 54: - return 'Ens. Médio - 4ª série'; // equivalent to 'EM 4 Série' - case 61: - return 'EJA - anos iniciais do Ens. Fundamental'; - case 62: - return 'EJA - anos finais do Ens. Fundamental'; - case 63: - return 'EJA - Ensino Médio'; - case 64: - return 'EJA semi-presencial'; - case 71: - return 'Educação Profissional'; - default: - return 'Não classificado'; - } -} +const libs = `${process.cwd()}/libs`; +const gender = require(`${libs}/convert/gender`); +const period = require(`${libs}/convert/period`); +const schoolYear = require(`${libs}/convert/schoolYear`); +const admDependency = require(`${libs}/convert/admDependency`); +const location = require(`${libs}/convert/location`); +const ethnicGroup = require(`${libs}/convert/ethnicGroup`); const ids = { gender_id: gender, period_id: period, - school_year_id: schoolYear + school_year_id: schoolYear, + education_level_id: schoolYear, + adm_dependency_id: admDependency, + adm_dependency_detailed_id: admDependency, + location_id: location, + ethnic_group_id: ethnicGroup }; function transform(removeId=false) { @@ -101,5 +37,8 @@ module.exports = { transform, gender, period, - schoolYear + schoolYear, + admDependency, + location, + ethnicGroup }; diff --git a/src/libs/routes/enrollment.js b/src/libs/routes/enrollment.js index 023b24e306406635ab106f0684062c58f2e7e1f1..35b22a005b034732f9407dd145d9479a74d660e3 100644 --- a/src/libs/routes/enrollment.js +++ b/src/libs/routes/enrollment.js @@ -93,48 +93,30 @@ rqf.addField({ where: false }).addValue({ name: 'adm_dependency', - table: 'dependencia_adm', - tableField: 'nome', - resultField: 'adm_dependency_name', + table: 'matricula', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency_id', where: { relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'dependencia_adm_id', - foreignTable: 'matricula' + type: 'integer' } }).addValue({ name: 'adm_dependency_detailed', - table: 'dependencia_adm', - tableField: 'nome', - resultField: 'adm_dependency_detailed_name', + table: 'matricula', + tableField: 'dependencia_adm_priv', + resultField: 'adm_dependency_detailed_id', where: { relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'dependencia_adm_priv', - foreignTable: 'matricula' + type: 'integer' } }).addValue({ name: 'education_level', - table: 'serie_ano', - tableField: 'nome', - resultField: 'education_level_name', + table: 'matricula', + tableField: 'serie_ano_id', + resultField: 'education_level_id', where: { relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'serie_ano_id', - foreignTable: 'matricula' + type: 'integer' } }).addValue({ name: 'region', @@ -198,18 +180,12 @@ rqf.addField({ } }).addValue({ name: 'location', - table: 'localizacao', - tableField: 'descricao', - resultField: 'location_name', + table: 'matricula', + tableField: 'localizacao_id', + resultField: 'location_id', where: { relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'localizacao_id', - foreignTable: 'matricula' + type: 'integer' } }).addValue({ name: 'min_year', @@ -243,18 +219,12 @@ rqf.addField({ } }).addValue({ name: 'ethnic_group', - table: 'cor_raca', - tableField: 'nome', - resultField: 'ethnic_group_name', + table: 'matricula', + tableField: 'cor_raca_id', + resultField: 'ethnic_group_id', where: { relation: '=', - type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'cor_raca_id', - foreignTable: 'matricula' + type: 'integer' } }).addValue({ name: 'period', diff --git a/src/test/enrollment.js b/src/test/enrollment.js index daad36c46f3d3e2496ae7d105eb054e7adb3cc8e..c0f2632685448491c3d1a62b698ed0540e3dfbed 100644 --- a/src/test/enrollment.js +++ b/src/test/enrollment.js @@ -180,7 +180,7 @@ describe('request enrollments', () => { it('should list enrollments with valid dimensions', (done) => { chai.request(server) - .get('/api/v1/enrollment?dims=region,state,adm_dependency,location&filter=min_year:2014,region:4') + .get('/api/v1/enrollment?dims=region,state,adm_dependency,location,gender,period,education_level,location,ethnic_group') .end((err, res) => { res.should.have.status(200); res.should.be.json;