I've a nested array to represent UI from a dynamic report template, but this array (JSONB) contains UUID for each field. I needed to transform this nested array with UUID into a same structure array but with the object for the respective fields.
EG: report_template:[[UUID, UUID], [UUID, UUID], UUID]
Expected outcome: [[{id: UUID, type: 'INPUT', label: 'last Name' }, {id: UUID, type: 'NUMBER', label: 'Age'}], [{id: UUID, type: 'DATE', label: 'Date'}, {id: UUID, type: 'INPUT', label: 'first Name'}], {id: UUID, type: 'INPUT', label: 'middle name'}]
I'm using a Postgres database with version 12, and Hasura for backend.
UPDATED: Here's a bit more details to help understand the structure.
I've a table called report_template_fields
with this structure:
{ id: 13ea9020-0013-4ab6-b22f-002cddb33c63, name: "First Name", type: TEXT }, { id: 13ea9020-0013-4ab6-b22f-002cddb33c63, name: "Last Name", type: TEXT }
While I'm using a jsonB in other table to keep the structure from the report template, called report_template
{ id: cd72bca9-9d9c-4386-8b4e-00e8e29c4a3a, name: "Default Template", fields: [["13ea9020-0013-4ab6-b22f-002cddb33c63", "5d368103-7400-477a-8f3c-ed51c647cb7c"] }
Wanted to build a computed function to give the relationships between report_template_fields
to report_template
.
Where fields would be: [[{ id: 13ea9020-0013-4ab6-b22f-002cddb33c63, name: "First Name", type: TEXT }, { id: 13ea9020-0013-4ab6-b22f-002cddb33c63, name: "Last Name", type: TEXT }']]