diff --git a/src/libs/routes_v1/basicEducationConclusion.js b/src/libs/routes_v1/basicEducationConclusion.js index a30c3afd4fb5b3425db83ebea2d122097af9f87f..3b22f4d3a96eabb0fcd2987a93be342e14854373 100644 --- a/src/libs/routes_v1/basicEducationConclusion.js +++ b/src/libs/routes_v1/basicEducationConclusion.js @@ -36,9 +36,9 @@ const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); const id2str = require(`${libs}/middlewares/id2str`); -const config = require(`${libs}/config`); +const config = require(`${libs}/config`); -const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; +const cache = require('apicache').options({ debug: config.debug, statusCodes: { include: [200] } }).middleware; let rqf = new ReqQueryFields(); @@ -46,8 +46,8 @@ basicEducationConclusion.use(cache('15 day')); basicEducationConclusion.get('/years', (req, res, next) => { req.sql.from('pnad_novo') - .field('DISTINCT pnad_novo.ano_ref', 'year') - .where('pnad_novo.ano_ref >= 2019') + .field('DISTINCT pnad_novo.ano_ref', 'year') + .where('pnad_novo.ano_ref >= 2019') next(); }, query, response('years')); @@ -60,7 +60,7 @@ basicEducationConclusion.get('/illiteracy', (req, res, next) => { }); } - req.result.push({id: 9, name: id2str.illiteracy(9)}); + req.result.push({ id: 9, name: id2str.illiteracy(9) }); next(); }, response('illiteracy')); @@ -73,7 +73,7 @@ basicEducationConclusion.get('/years_of_study', (req, res, next) => { }); } - req.result.push({id: 99, name: id2str.yearsOfStudy(99)}); + req.result.push({ id: 99, name: id2str.yearsOfStudy(99) }); next(); }, response('years_of_study')); @@ -85,7 +85,7 @@ basicEducationConclusion.get('/instruction_level', (req, res, next) => { id: i, name: id2str.instructionLevel(i) }); } - req.result.push({id: 99, name: id2str.instructionLevel(99)}); + req.result.push({ id: 99, name: id2str.instructionLevel(99) }); next(); }, response('instruction_level')); @@ -96,7 +96,7 @@ basicEducationConclusion.get('/new_pnad_adm_dependency', (req, res, next) => { id: i, name: id2str.newPnadAdmDependency(i) }); } - req.result.push({id: 99, name: id2str.newPnadAdmDependency(99)}); + req.result.push({ id: 99, name: id2str.newPnadAdmDependency(99) }); next(); }, response('new_pnad_adm_dependency')); @@ -115,9 +115,9 @@ basicEducationConclusion.get('/cap_code', (req, res, next) => { req.result = [] for (let i = 11; i < 54; i++) { if (id2str.capitalCode(i) !== 'Não informado') { - req.result.push({ - id: i, name: id2str.capitalCode(i) - }); + req.result.push({ + id: i, name: id2str.capitalCode(i) + }); } } @@ -128,12 +128,12 @@ basicEducationConclusion.get('/metro_code', (req, res, next) => { req.result = [] for (let i = 13; i < 53; i++) { if (id2str.metroCode(i) !== 'Não informado') { - req.result.push({ - id: i, name: id2str.metroCode(i) - }); + req.result.push({ + id: i, name: id2str.metroCode(i) + }); } } - req.result.push({id: 99, name: id2str.metroCode(99)}); + req.result.push({ id: 99, name: id2str.metroCode(99) }); next(); }, response('metro_code')); @@ -147,7 +147,7 @@ basicEducationConclusion.get('/attended_modality', (req, res, next) => { } // Remove the option with id equals 10 => This option exists in the database, a better solution to this would be remove the option from the database req.result.splice(req.result.findIndex((item) => item.id === 10), 1); - req.result.push({id: 99, name: id2str.attendedModality(99)}); + req.result.push({ id: 99, name: id2str.attendedModality(99) }); next(); }, response('attended_modality')); @@ -158,7 +158,7 @@ basicEducationConclusion.get('/income_range', (req, res, next) => { id: i, name: id2str.incomeRange(i) }); } - req.result.push({id: 10, name: id2str.incomeRange(10)}); + req.result.push({ id: 9, name: id2str.incomeRange(9) }); next(); }, response('income_range')); @@ -189,7 +189,7 @@ basicEducationConclusion.get('/new_pnad_ethnic_group', (req, res, next) => { id: i, name: id2str.ethnicGroupNewPnad(i) }); } - req.result.push({id: 9, name: id2str.ethnicGroupNewPnad(9)}); + req.result.push({ id: 9, name: id2str.ethnicGroupNewPnad(9) }); next(); }, response('new_pnad_ethnic_group')); @@ -200,7 +200,7 @@ basicEducationConclusion.get('/bolsa_familia', (req, res, next) => { id: i, name: id2str.attendsSchool(i) }); } - req.result.push({id: 9, name: id2str.attendsSchool(9)}); + req.result.push({ id: 9, name: id2str.attendsSchool(9) }); next(); }, response('bolsa_familia')); @@ -211,7 +211,7 @@ basicEducationConclusion.get('/modality', (req, res, next) => { id: i, name: id2str.modality(i) }); } - req.result.push({id: 99, name: id2str.modality(99)}); + req.result.push({ id: 99, name: id2str.modality(99) }); next(); }, response('modality')); @@ -222,8 +222,8 @@ basicEducationConclusion.get('/modality_shift', (req, res, next) => { id: i, name: id2str.modalityShift(i) }); } - req.result.push({id: 9, name: id2str.modalityShift(9)}); - req.result.push({id: 99, name: id2str.modalityShift(99)}); + req.result.push({ id: 9, name: id2str.modalityShift(9) }); + req.result.push({ id: 99, name: id2str.modalityShift(99) }); next(); }, response('modality_shift')); @@ -236,7 +236,7 @@ basicEducationConclusion.get('/state', (req, res, next) => { }); } } - req.result.push({id: 99, name: id2str.stateName(99)}); + req.result.push({ id: 99, name: id2str.stateName(99) }); next(); }, response('state')); @@ -425,12 +425,12 @@ rqf.addField({ }).addValue({ name: 'income_range', table: 'pnad_novo', - tableField: 'faixa_rendimento_aux_tx', + tableField: 'faixa_rendimento_aux', resultField: 'income_range_id', where: { relation: '=', type: 'integer', - field: 'faixa_rendimento_aux_tx' + field: 'faixa_rendimento_aux' } }).addValue({ name: 'gender', @@ -544,26 +544,26 @@ function matchQueries(queryPartial, queryTotal) { newObj[key] = result[key]; }); let index = keys.indexOf('total'); - if(index > -1) keys.splice(index, 1); + if (index > -1) keys.splice(index, 1); let objMatch = null; - for(let i = 0; i < queryPartial.length; ++i) { + for (let i = 0; i < queryPartial.length; ++i) { let partial = queryPartial[i]; let foundMatch = true; - for(let j = 0; j < keys.length; ++j) { + for (let j = 0; j < keys.length; ++j) { let key = keys[j]; - if(partial[key] !== result[key]) { + if (partial[key] !== result[key]) { foundMatch = false; break; } } - if(foundMatch) { + if (foundMatch) { objMatch = partial; break; } } - if(objMatch) { + if (objMatch) { newObj.denominator = result.total; newObj.partial = objMatch.total; newObj.total = (objMatch.total / result.total) * 100; @@ -576,10 +576,10 @@ function matchQueries(queryPartial, queryTotal) { basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.querySet = []; - + // Subquery para total_pop_maior_19 com filtros dinâmicos let totalPopMaior19 = req.sql.clone(); - totalPopMaior19.from("pnad_novo") + totalPopMaior19.from("pnad_novo") .field("ano_ref", "year") .field("SUM(peso_domicilio_pessoas_com_cal)", "total") .where("idade_morador_31_03 >= 19") @@ -589,7 +589,7 @@ basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => // Subquery para total_pop_ed_bas_maior_19 com filtros dinâmicos let totalPopEdBasMaior19 = req.sql.clone(); - totalPopEdBasMaior19.from("pnad_novo") + totalPopEdBasMaior19.from("pnad_novo") .field("ano_ref", "year") .field("SUM(peso_domicilio_pessoas_com_cal)", "total") .where("idade_morador_31_03 >= 19") @@ -598,11 +598,6 @@ basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => .group("ano_ref") .order("ano_ref"); - if (req.query.dims && req.query.dims.includes("income_range")) { - totalPopMaior19.where("faixa_rendimento_aux_tx is not null"); - totalPopEdBasMaior19.where("faixa_rendimento_aux_tx is not null"); - } - if (req.query.dims && req.query.dims.includes("cap_code")) { totalPopMaior19.where("cod_cap < 99"); } @@ -612,10 +607,10 @@ basicEducationConclusion.get('/', rqf.parse(), rqf.build(), (req, res, next) => next(); }, multiQuery, (req, res, next) => { - // The multiple requests are made. Then we need to calculate the percetange. So the function - // below is used - let newObj = matchQueries(req.result[0], req.result[1]); - req.result = newObj; + // The multiple requests are made. Then we need to calculate the percetange. So the function + // below is used + let newObj = matchQueries(req.result[0], req.result[1]); + req.result = newObj; next(); }, id2str.transform(false), response('basic_education_conclusion'));