I have API data that isn't optimized in its structure
I cannot request backend devs restructure it, so I'm looking to tidy the model locally before use in my Angular 2 application.
As an example I receive a flat object which contains tables and user data
{$id: "400", sqlTable: "Customer", admin: 1, test: 3}
It would be best to filter these and place Users into a sub object to speed up rendering without conditional testing etc.
Preferred structure:
"sqlTable":"value",
"Users":[
"user1name":permission,
"user2name":permission
]
So from original data:
- $id is unimportant (so was deleted)
- sqlTable is the table name
- admin and test are Users
So if we delete the $id, the "rule set" is anything that isn't sqlTable is a User and should be moved to Sub Object called Users.
It would be appreciated if anyone can provide example JS/TS on how to move the data (key/value) into the sub structure based on this ruleset.
Full returning data as requested:
{
"$id":"399",
"IsFailure":false,
"IsSuccess":true,
"Value":[
{
"$id":"400",
"sqlTable":"Customer",
"admin":1,
"test":null
},
{
"$id":"401",
"sqlTable":"CustomerAddress",
"admin":null,
"test":null
},
{
"$id":"402",
"sqlTable":"NewTable",
"admin":null,
"test":null
}
]
}
I would do some transformations to the data before rendering, something like this: