Commit ea9d7bc5 authored by Vytor Calixto's avatar Vytor Calixto 👾

Try to reutilize dims filed

parent 943702db
......@@ -229,8 +229,11 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
next();
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
delete req.dims;
delete req.filter;
next();
}, rqf.parse(), rqf.build(), (req, res, next) => {
console.log('dims', req.dims);
req.classroom = req.result;
let classroom = [];
......@@ -243,19 +246,30 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
let hashSet = new Set();
while (i < req.classroom.length) {
let classroom = req.classroom[i];
// Cria hash única para cada cidade, dado um ano
let hash = '' + classroom.year + classroom.city_id;
// Cria hash única para cada espacialidade, dado um ano
let hash = '' + classroom.year;
if(req.dims.state) hash+= '' + classroom.state_id;
if(req.dims.city) hash+= '' + classroom.state_id + classroom.city_id;
// Estrutura do objeto do resultado final
let obj = {
year: classroom.year,
name: classroom.name,
state_id: classroom.state_id,
state_name: classroom.state_name,
city_id: classroom.city_id,
city_name: classroom.city_name,
locations: []
};
if(req.dims.state) {
obj.state_id = classroom.state_id;
obj.state_name = classroom.state_name;
}
console.log('city', req.dims.city);
if(req.dims.city) {
obj.state_id = classroom.state_id;
obj.state_name = classroom.state_name;
obj.city_id = classroom.city_id;
obj.city_name = classroom.city_name;
}
let currentClassroomObj = null;
if( !hashSet.has(hash) ) {
hashSet.add(hash);
......@@ -388,9 +402,9 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => {
++i;
}
// TODO: agregar por estado e brasil
if(req.query['state']) {
if(req.dims.state) {
console.log('ESTADO!!!!');
} else if(!req.query['city']) {
} else if(!req.dims.city) {
console.log('BRASIL!!!');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment