Skip to content
Snippets Groups Projects
Commit d5525dd5 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Add subtraction

parent e8eee33c
No related branches found
No related tags found
No related merge requests found
Pipeline #16353 failed
......@@ -254,6 +254,59 @@ rqf.addField({
}
});
function matchQueries(queryTotal, queryPartial) {
let match = [];
queryPartial.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];
let foundMatch = true;
for(let j = 0; j < keys.length; ++j) {
let key = keys[j];
if(total[key] !== result[key]) {
foundMatch = false;
break;
}
}
if(foundMatch) {
objMatch = total;
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;
}
employeesApp.get('/', rqf.parse(), (req, res, next) => {
req.allEmployees = {}
req.allTeacher = {}
......@@ -296,12 +349,8 @@ employeesApp.get('/', rqf.parse(), (req, res, next) => {
}, rqf.build(), query, id2str.transform(), (req, res, next) => {
req.allTeacher = req.result;
req.result = []
req.result.push(req.allEmployees)
req.result.push(req.allTeacher)
console.log(req.allEmployees)
console.log(req.allTeacher)
let aux_employees = matchQueries(req.allTeacher, req.allEmployees);
req.result = aux_employees;
next();
}, response('employees'));
......
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