refactor: wip migrate ot nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-19 12:48:24 +02:00
parent bfff56c470
commit 93bf6d9d3d
73 changed files with 4683 additions and 96 deletions

View File

@@ -0,0 +1,24 @@
export 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;
};