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

Merge branch 'fix_add_missing' into development

parents a497d3bb fb32bf42
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -5,7 +5,7 @@ module.exports = function addMissing(rqf){
if(dims.length != 2) return next();
if(req.filter.min_year != req.filter.max_year) return next();
if(req.result.length === 0) return next();
let result = req.result;
let dimsValues = {};
result.forEach((r) => {
......@@ -19,31 +19,31 @@ module.exports = function addMissing(rqf){
}
})
});
let G = {};
let rqfName = rqf.fieldValues[dims[0]].resultField;
let rqfName2 = rqf.fieldValues[dims[1]].resultField;
G[rqfName] = {};
dimsValues[rqfName].forEach((value) => {
let secondDim = {};
dimsValues[rqfName2].forEach((dValue) => {
secondDim[dValue] = false;
});
G[rqfName][value] = {};
G[rqfName][value][rqfName2] = secondDim;
});
result.forEach((r) => {
let resultDim1 = r[rqfName];
let resultDim2 = r[rqfName2];
G[rqfName][resultDim1][rqfName2][resultDim2] = true;
});
Object.keys(G[rqfName]).forEach((dim1Value) => {
Object.keys(G[rqfName][dim1Value][rqfName2]).forEach((dim2Value) => {
console.log(dim2Value);
let value = G[rqfName][dim1Value][rqfName2][dim2Value];
if(!value) {
let newEntry = Object.assign({}, result[0], {[rqfName]: parseInt(dim1Value, 10), [rqfName2]: parseInt(dim2Value, 10), total: 0});
......@@ -55,14 +55,16 @@ module.exports = function addMissing(rqf){
if(r[rqfName] > newEntry[rqfName]) break;
if(r[rqfName] == newEntry[rqfName] && r[rqfName2] > newEntry[rqfName2]) break;
}
let newResult = [...result.slice(0, index), newEntry, ...result.slice(index, result.length)];
result = newResult;
if (newEntry.dim1Value != undefined && newEntry.dim2Value != undefined) {
let newResult = [...result.slice(0, index), newEntry, ...result.slice(index, result.length)];
result = newResult;
}
}
});
});
req.result = result;
next();
};
};
\ No newline at end of file
};
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