diff --git a/src/libs/routes/employees.js b/src/libs/routes/employees.js index fe143808b83d94fa76c4b26d5c640fd4aeeaddcf..8e1219d28186725ab0eaf9dd34ed4f729c952980 100644 --- a/src/libs/routes/employees.js +++ b/src/libs/routes/employees.js @@ -256,54 +256,40 @@ rqf.addField({ function matchQueries(queryTotal, queryPartial) { let match = []; - queryPartial.forEach((result) => { + queryTotal.forEach((result) => { let newObj = {}; let keys = Object.keys(result); keys.forEach((key) => { newObj[key] = result[key]; }); - // console.log('NEW OBJ'); - // console.log(newObj); - // remove total let index = keys.indexOf('total'); if(index > -1) keys.splice(index, 1); - // remove education_level_basic_id - index = keys.indexOf('education_level_basic_id'); - if(index > -1) keys.splice(index, 1); - // remove education_level_basic_name - index = keys.indexOf('education_level_basic_name'); - if(index > -1) keys.splice(index, 1); let objMatch = null; - for(let i = 0; i < queryTotal.length; ++i) { - let total = queryTotal[i]; + for(let i = 0; i < queryPartial.length; ++i) { + let partial = queryPartial[i]; let foundMatch = true; for(let j = 0; j < keys.length; ++j) { let key = keys[j]; - if(total[key] !== result[key]) { + if(partial[key] !== result[key]) { foundMatch = false; break; } } if(foundMatch) { - objMatch = total; + objMatch = partial; break; } } if(objMatch) { - // console.log('MATCH!!!!'); - // console.log(objMatch); newObj.total = result.total - objMatch.total; newObj.total_employees = result.total; newObj.total_teachers = objMatch.total match.push(newObj); } }); - // console.log('TAMANHOS'); - // console.log(queryTotal.length); - // console.log(queryPartial.length); - // console.log(match.length); + return match; } @@ -349,7 +335,7 @@ employeesApp.get('/', rqf.parse(), (req, res, next) => { }, rqf.build(), query, id2str.transform(), (req, res, next) => { req.allTeacher = req.result; - let aux_employees = matchQueries(req.allTeacher, req.allEmployees); + let aux_employees = matchQueries(req.allEmployees, req.allTeacher); req.result = aux_employees; next(); }, response('employees'));