I am a beginner in TypeScript and tb in JavaScript, so I confess I do not have much knowledge of the language, so 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 something 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 Parent Object contains all of its children within, and so on.
Can anyone help me?