Skip to content
Snippets Groups Projects
Commit 2bf3697a authored by lgtg20's avatar lgtg20
Browse files

Merge branch 'fix_non_aggregate_filters' into 'development'

Adds keys for non aggregate fields in the convert obj

See merge request !412
parents f646d1b6 c6553bc1
Branches
No related tags found
3 merge requests!417[ADD] Indicator "Taxa de Atendimento Educacional" updated on production!,!416[ADD] Route almost ready, some tests needed. Comments added and filters that...,!412Adds keys for non aggregate fields in the convert obj
...@@ -2,21 +2,25 @@ const id2str = require(`./id2str`); ...@@ -2,21 +2,25 @@ const id2str = require(`./id2str`);
/* /*
Middleware que tem como função formatar dados agregados. Middleware que tem como função formatar dados agregados.
Dados agregados não podem ser "puxados" do banco de dados da mesma maneira que os dados tradicioanis, dessa maneira é Dados agregados não podem ser 'puxados' do banco de dados da mesma maneira que os dados tradicioanis, dessa maneira é
necessário formatá-los para que sigam o padrão. necessário formatá-los para que sigam o padrão.
*/ */
// Faz o mapeamento dos filtros com seus respectivos "id2str" // Faz o mapeamento dos filtros com seus respectivos 'id2str'
const convert = { const convert = {
"adm_dependency_detailed": "admDependencyPriv", adm_dependency_detailed: 'admDependencyPriv',
"age_range": "ageRangeAggregate", location: 'location',
"gender": "gender", diff_location: 'diffLocation',
"ethnic_group": "ethnicGroup", region: 'regionCode',
"education_level_mod_agg": "educationLevelModAgg", state: 'stateName',
'integral_time_agg': 'integralTime', age_range: 'ageRangeAggregate',
'period_agg': 'period', gender: 'gender',
'modality_integral_time': 'educationLevelBasic', ethnic_group: 'ethnicGroup',
'especial_education': 'especialEducation' education_level_mod_agg: 'educationLevelModAgg',
integral_time_agg: 'integralTime',
period_agg: 'period',
modality_integral_time: 'educationLevelBasic',
especial_education: 'especialEducation'
} }
function aggregateData(req, res, next) { function aggregateData(req, res, next) {
...@@ -30,14 +34,13 @@ function aggregateData(req, res, next) { ...@@ -30,14 +34,13 @@ function aggregateData(req, res, next) {
// Verifica se o filtro passado está presente nos filtros agregados // Verifica se o filtro passado está presente nos filtros agregados
fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field}); fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field});
console.log(convert[currentAggregateField])
if (currentAggregateField) { if (currentAggregateField) {
req.result.forEach((r) => { req.result.forEach((r) => {
// Alguns filtros começam com o id = 0 outros id = 1 // Alguns filtros começam com o id = 0 outros id = 1
id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1; id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1;
for (const property in r) { for (const property in r) {
// Dados agregados são identificados com a substring "total_" em sua chave // Dados agregados são identificados com a substring 'total_' em sua chave
if (property.includes("total_")) { if (property.includes('total_')) {
let data = { let data = {
total: r[property], total: r[property],
year: r.year, year: r.year,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment