Commit 3e8dbb90 authored by Fernando Erd's avatar Fernando Erd 👌

Fix add missing

parent 696127e2
Pipeline #15400 failed with stage
in 60 minutes and 4 seconds
...@@ -5,7 +5,7 @@ module.exports = function addMissing(rqf){ ...@@ -5,7 +5,7 @@ module.exports = function addMissing(rqf){
if(dims.length != 2) return next(); if(dims.length != 2) return next();
if(req.filter.min_year != req.filter.max_year) return next(); if(req.filter.min_year != req.filter.max_year) return next();
if(req.result.length === 0) return next(); if(req.result.length === 0) return next();
let result = req.result; let result = req.result;
let dimsValues = {}; let dimsValues = {};
result.forEach((r) => { result.forEach((r) => {
...@@ -19,29 +19,29 @@ module.exports = function addMissing(rqf){ ...@@ -19,29 +19,29 @@ module.exports = function addMissing(rqf){
} }
}) })
}); });
let G = {}; let G = {};
let rqfName = rqf.fieldValues[dims[0]].resultField; let rqfName = rqf.fieldValues[dims[0]].resultField;
let rqfName2 = rqf.fieldValues[dims[1]].resultField; let rqfName2 = rqf.fieldValues[dims[1]].resultField;
G[rqfName] = {}; G[rqfName] = {};
dimsValues[rqfName].forEach((value) => { dimsValues[rqfName].forEach((value) => {
let secondDim = {}; let secondDim = {};
dimsValues[rqfName2].forEach((dValue) => { dimsValues[rqfName2].forEach((dValue) => {
secondDim[dValue] = false; secondDim[dValue] = false;
}); });
G[rqfName][value] = {}; G[rqfName][value] = {};
G[rqfName][value][rqfName2] = secondDim; G[rqfName][value][rqfName2] = secondDim;
}); });
result.forEach((r) => { result.forEach((r) => {
let resultDim1 = r[rqfName]; let resultDim1 = r[rqfName];
let resultDim2 = r[rqfName2]; let resultDim2 = r[rqfName2];
G[rqfName][resultDim1][rqfName2][resultDim2] = true; G[rqfName][resultDim1][rqfName2][resultDim2] = true;
}); });
Object.keys(G[rqfName]).forEach((dim1Value) => { Object.keys(G[rqfName]).forEach((dim1Value) => {
Object.keys(G[rqfName][dim1Value][rqfName2]).forEach((dim2Value) => { Object.keys(G[rqfName][dim1Value][rqfName2]).forEach((dim2Value) => {
let value = G[rqfName][dim1Value][rqfName2][dim2Value]; let value = G[rqfName][dim1Value][rqfName2][dim2Value];
...@@ -55,14 +55,16 @@ module.exports = function addMissing(rqf){ ...@@ -55,14 +55,16 @@ module.exports = function addMissing(rqf){
if(r[rqfName] > newEntry[rqfName]) break; if(r[rqfName] > newEntry[rqfName]) break;
if(r[rqfName] == newEntry[rqfName] && r[rqfName2] > newEntry[rqfName2]) break; if(r[rqfName] == newEntry[rqfName] && r[rqfName2] > newEntry[rqfName2]) break;
} }
let newResult = [...result.slice(0, index), newEntry, ...result.slice(index, result.length)]; if (newEntry.dim1Value != undefined && newEntry.dim2Value != undefined) {
result = newResult; let newResult = [...result.slice(0, index), newEntry, ...result.slice(index, result.length)];
result = newResult;
}
} }
}); });
}); });
req.result = result; req.result = result;
next(); next();
}; };
}; };
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment