From 5d356af14e8ad78f4b8ed216ae797296a3fb1be1 Mon Sep 17 00:00:00 2001 From: Vytor Calixto <vytorcalixto@gmail.com> Date: Wed, 13 Jun 2018 09:11:17 -0300 Subject: [PATCH] Fix santa catarina bug --- src/libs/routes/classroomCount.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/routes/classroomCount.js b/src/libs/routes/classroomCount.js index 65fbceed..afa4d64d 100644 --- a/src/libs/routes/classroomCount.js +++ b/src/libs/routes/classroomCount.js @@ -428,6 +428,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { // Fazer "merge" do array locations da cidade com o da agregação if(currentObj.locations.length == 0) { + // Pode ser que a cidade atual tenha menos localidades que o total (só urbana ou só rural) currentObj.locations = [...city.locations]; } else { let j = 0; @@ -444,10 +445,16 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { } else if(cityLocation.location_id > currentLocation.location_id) { ++k; currentLocation = currentObj.locations[k]; + // Se a localidade da cidade é maior que a localidade do objeto atual E o vetor de localidades do objeto atual + // acaba, então esta localidade falta no objeto atual, pois as localidades estão ordenadas + if(typeof currentLocation == 'undefined' && typeof cityLocation !== 'undefined') { + currentObj.locations[k] = cityLocation; + currentLocation = currentObj.locations[k]; + } continue; } - // Fazer merge do array education_level + // Fazer "merge" do array education_level if(currentLocation.education_level.length == 0) { currentLocation.education_level = [...cityLocation.education_level]; } else { @@ -492,7 +499,7 @@ classroomCountApp.post('/', rqf.parse(), (req, res, next) => { } } - req.result = /*{result, enrollments} //*/ reduction || result; + req.result = {result: reduction, enrollments} // reduction || result; next(); }, response('classroom_count')); -- GitLab