diff --git a/src/libs/routes_v1/yearsOfStudy.js b/src/libs/routes_v1/yearsOfStudy.js index cc76ca34265d58469ecff6e538d717421416dc58..f3cf6ec3a8429e950711292cc429d50e2ab1b075 100644 --- a/src/libs/routes_v1/yearsOfStudy.js +++ b/src/libs/routes_v1/yearsOfStudy.js @@ -300,14 +300,14 @@ rqf.addField({ foreignTable: 'pnad_novo' } }).addValue({ - name: 'years_of_study', + name: 'location', table: 'pnad_novo', - tableField: 'anos_de_estudo', - resultField: 'years_of_study_id', + tableField: 'situacao_domicilio', + resultField: 'location_id', where: { relation: '=', type: 'integer', - field: 'anos_de_estudo' + field: 'situacao_domicilio' } }).addValue({ name: 'instruction_level', @@ -378,7 +378,7 @@ rqf.addField({ relation: '=', type: 'integer', field: 'turno_nivel_etapa' - } + } }).addValue({ name: 'bolsa_familia', table: 'pnad_novo', @@ -482,7 +482,7 @@ rqf.addField({ }).addField({ name: 'search', field: false, - where: true + where: true }).addValueToField({ name: 'name', table: 'pnad_novo', @@ -514,6 +514,15 @@ rqf.addField({ PnadNovoApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + let teste = "pnad_novo.ano_ref = media.ano_ref" + if (req.dims) { + for (i in req.dims) { + teste += ` and pnad_novo.${i.table} = media.${i.tableField}` + } + } + + console.log(teste) + let mean = squel.select() .from('pnad_novo') .field('pnad_novo.ano_ref', 'ano_ref') @@ -525,7 +534,7 @@ PnadNovoApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('pnad_novo.ano_ref', 'year') .field('media.media_anos_estudo', 'mean') .field('SQRT(SUM((POWER(pnad_novo.anos_de_estudo - media.media_anos_estudo, 2) * pnad_novo.peso_domicilio_pessoas_com_cal)) / SUM(pnad_novo.peso_domicilio_pessoas_com_cal))', 'std_dev') - .join(mean, 'media', 'pnad_novo.ano_ref = media.ano_ref') + .join(mean, 'media', teste) .where('pnad_novo.ano_ref >= 2019') .group('pnad_novo.ano_ref') .group('media.media_anos_estudo')