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
No related branches found
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`);
/*
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.
*/
// Faz o mapeamento dos filtros com seus respectivos "id2str"
// Faz o mapeamento dos filtros com seus respectivos 'id2str'
const convert = {
"adm_dependency_detailed": "admDependencyPriv",
"age_range": "ageRangeAggregate",
"gender": "gender",
"ethnic_group": "ethnicGroup",
"education_level_mod_agg": "educationLevelModAgg",
'integral_time_agg': 'integralTime',
'period_agg': 'period',
'modality_integral_time': 'educationLevelBasic',
'especial_education': 'especialEducation'
adm_dependency_detailed: 'admDependencyPriv',
location: 'location',
diff_location: 'diffLocation',
region: 'regionCode',
state: 'stateName',
age_range: 'ageRangeAggregate',
gender: 'gender',
ethnic_group: 'ethnicGroup',
education_level_mod_agg: 'educationLevelModAgg',
integral_time_agg: 'integralTime',
period_agg: 'period',
modality_integral_time: 'educationLevelBasic',
especial_education: 'especialEducation'
}
function aggregateData(req, res, next) {
......@@ -30,14 +34,13 @@ function aggregateData(req, res, next) {
// Verifica se o filtro passado está presente nos filtros agregados
fields.forEach(field => {if (aggregateFields.includes(field)) currentAggregateField = field; else currentNonAggregateField = field});
console.log(convert[currentAggregateField])
if (currentAggregateField) {
req.result.forEach((r) => {
// Alguns filtros começam com o id = 0 outros id = 1
id = ['ethnic_group', 'integral_time_agg'].includes(currentAggregateField) ? 0 : 1;
for (const property in r) {
// Dados agregados são identificados com a substring "total_" em sua chave
if (property.includes("total_")) {
// Dados agregados são identificados com a substring 'total_' em sua chave
if (property.includes('total_')) {
let data = {
total: r[property],
year: r.year,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment