3
I am beginner in Typescript and tb in Javascript, so I confess not to have much knowledge of the language, therefore, I will describe my problem.
I have the following table in a Postgres database:
As you can see, a simple structure where one record references the other in a hierarchical parent-child structure.
What I need to do is a function in typescript that is recursive that returns an array with objects more or less like this:
[
{
id: 1,
filhos: [
{
id: 11,
filhos: null
},
{
id: 12,
filhos: [
{
id: 121,
filhos: null
},
{
id: 122,
filhos: null
},
{
id: 123,
filhos: null
},
{
id: 124,
filhos: null
}
]
}
]
},
{
id: 2,
filhos: [
{
id: 21,
filhos: null
},
{
id: 22,
filhos: null
},
{
id: 23,
filhos: null
}
]
}
]
Notice that the Father Object contains all its children within, and so on.
Can someone help me?