feat: Financial statements dependency graph calculate.

This commit is contained in:
Ahmed Bouhuolia
2020-05-23 06:47:00 +02:00
parent b2c9ac54f4
commit 17c1b6ad51
26 changed files with 2041 additions and 900 deletions

View File

@@ -72,6 +72,30 @@ const promiseSerial = (funcs) => {
Promise.resolve([]));
}
const flatToNestedArray = (data, config = { id: 'id', parentId: 'parent_id' }) => {
const map = {};
const nestedArray = [];
data.forEach((item) => {
map[item[config.id]] = item;
map[item[config.id]].children = [];
});
data.forEach((item) => {
const parentItemId = item[config.parentId];
if (!item[config.parentId]) {
nestedArray.push(item);
}
if(parentItemId) {
map[parentItemId].children.push(item);
}
});
return nestedArray;
}
export {
hashPassword,
origin,
@@ -80,4 +104,5 @@ export {
mapValuesDeep,
mapKeysDeep,
promiseSerial,
flatToNestedArray,
};