mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: Financial statements dependency graph calculate.
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user