diff --git a/src/libs/routes/classroomCount.js b/src/libs/routes/classroomCount.js index 65fbceedfcb1e8ce21060b249f20851873dce367..afa4d64da83fec1ad7713533fa14d4d526826502 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'));