diff --git a/src/libs/convert/ageRangeAll.js b/src/libs/convert/ageRangeAll.js index 1ad1c54ee82d26a9d93d9608b38e9cc624a82428..ebc2336ac35478cf950669b96ff2b3fcf35a5d7c 100644 --- a/src/libs/convert/ageRangeAll.js +++ b/src/libs/convert/ageRangeAll.js @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. */ -module.exports = function ageRange(id) { +module.exports = function ageRangeAll(id) { switch (id) { case 1: return '0 a 3 anos'; diff --git a/src/libs/routes_v1/superiorEducationConclusionTax.js b/src/libs/routes_v1/superiorEducationConclusionTax.js index 1f84f7b071048a4a3170244131a66c2ba6174d78..d345b2309c3ac627dcac6bc6742e001de287e169 100644 --- a/src/libs/routes_v1/superiorEducationConclusionTax.js +++ b/src/libs/routes_v1/superiorEducationConclusionTax.js @@ -111,7 +111,7 @@ superiorEducationConclusionTaxApp.get('/region', (req, res, next) => { next(); }, response('region')); -superiorEducationConclusionTaxApp.get('/cap_code', (req, res, next) => { +superiorEducationConclusionTaxApp.get('/cap_code_pnad', (req, res, next) => { req.result = [] for (let i = 11; i < 54; i++) { if (id2str.capitalCode(i) !== 'Não informado') { @@ -120,10 +120,8 @@ superiorEducationConclusionTaxApp.get('/cap_code', (req, res, next) => { }); } } - req.result.push({id: 99, name: id2str.capitalCode(99)}); - next(); -}, response('cap_code')); +}, response('cap_code_pnad')); superiorEducationConclusionTaxApp.get('/metro_code', (req, res, next) => { req.result = [] @@ -134,7 +132,6 @@ superiorEducationConclusionTaxApp.get('/metro_code', (req, res, next) => { }); } } - req.result.push({id: 99, name: id2str.metroCode(99)}); next(); }, response('metro_code')); @@ -160,6 +157,7 @@ superiorEducationConclusionTaxApp.get('/income_range', (req, res, next) => { }); } req.result.push({id: 10, name: id2str.incomeRange(10)}); + next(); }, response('income_range')); @@ -242,16 +240,17 @@ superiorEducationConclusionTaxApp.get('/state', (req, res, next) => { next(); }, response('state')); -superiorEducationConclusionTaxApp.get('/age_range', (req, res, next) => { +superiorEducationConclusionTaxApp.get('/age_range_all', (req, res, next) => { req.result = [] - for (let i = 1; i < 12; i++) { + for (let i = 7; i < 12; i++) { req.result.push({ id: i, name: id2str.ageRangeAll(i) }); } + console.log(req.result); next(); -}, response('age_range')); +}, response('age_range_all')); superiorEducationConclusionTaxApp.get('/location', (req, res, next) => { req.result = [] @@ -444,10 +443,10 @@ rqf.addField({ field: 'sexo' } }).addValue({ - name: 'cap_code', + name: 'cap_code_pnad', table: 'pnad_novo', tableField: 'cod_cap', - resultField: 'cap_code_id', + resultField: 'cap_code_pnad_id', where: { relation: '=', type: 'integer', @@ -575,9 +574,28 @@ function matchQueries(queryPartial, queryTotal) { return match; } +function whereCondition(req) { + let where = ""; + let filterId; + //const filters = req.query.filter.split(","); + const dims = req.query.dims; + if (dims && dims.includes("cap_code_pnad")){ + where += `pnad_novo.cod_cap <> 99`; + } + if (dims && dims.includes("income_range")){ + where += `pnad_novo.faixa_rendimento_aux_tx is not null`; + } + if (dims && dims.includes("age_range_superior")){ + where += `pnad_novo.faixa_etaria > 6`; + } + + return where; +} + superiorEducationConclusionTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { req.querySet = []; - + let where = whereCondition(req); + // Subquery para total_pop_maior_25 com filtros dinâmicos let totalPopMaior25ComSuperiorCompleto = req.sql.clone(); totalPopMaior25ComSuperiorCompleto.from("pnad_novo") @@ -586,9 +604,10 @@ superiorEducationConclusionTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, .where("idade_morador_31_03 >= 25") .where("nivel_de_instruc_mais_elevad_para_o_fundam_com_duracao_9_anos = 7") .where("ano_ref >= 2019") + .where(`${where}`) .group("ano_ref") .order("ano_ref"); - + // Subquery para total_pop_maior_25 com filtros dinâmicos let totalPopMaior25 = req.sql.clone(); @@ -597,14 +616,10 @@ superiorEducationConclusionTaxApp.get('/', rqf.parse(), rqf.build(), (req, res, .field("SUM(peso_domicilio_pessoas_com_cal)", "total") .where("idade_morador_31_03 >= 25") .where("ano_ref >= 2019") + .where(`${where}`) .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"); - // } - req.querySet.push(totalPopMaior25ComSuperiorCompleto); req.querySet.push(totalPopMaior25);