I've tried searching the interwebs and accept that I may be ignorant of the proper terminology required to find the solution. I'm OK with references to reading materials, but I'm not exactly sure where to start.
For the stack, I'm using Angular + NestJS. Plan to integrate TypeORM using Postgres as the database.
I have the following entities where a Budget has one Project and a Project may have many Budgets:
export interface Budget {
id: number;
description: string;
project_id: number;
budget_type: string;
budget_status: string;
}
export interface Project {
id: number;
project_number: string;
project_title: string;
project_status: string;
client: string;
}
For this scenario, I want to show a list of Budgets in a angular material table and show the "project_number" in the table instead of the "project_id".
- Should I modify the Budget interface definition to return it's Project?
OR
- Should I have the app request the Project resource through the API?
In general, for entities that hold references to other entities with an id. Should I include those entities in the response from the API or nest them into the response.
Should I modify the Budget interface definition to return it's Project? Concern: For more highly nested objects, there could be more data than what's actually needed.
{
"budgets": [{
"id": 1,
"description": "platea dictumst",
"project": {
"id": 3,
"project_number": "19139",
"project_title": "neque aenean auctor gravida",
"project_status": "Lost",
"client": "Eabox"
},
"budget_type": "Change Order",
"budget_status": "Approved"
},
{
"id": 2,
"description": "et commodo vulputate justo in blandit",
"project": {
"id": 78,
"project_number": "19356",
"project_title": "et eros vestibulum ac est",
"project_status": "Active",
"client": "Kimia"
},
"budget_type": "Original",
"budget_status": "Lost"
}
]
}
Should I have the app request the Project resource through the API? Concern: If I have 100 budgets, this would be an additional 100 calls to the API while the app is waiting for the table to load.
{
"budgets": [
{
"id": 1,
"description": "platea dictumst",
"project_id": 3,
"budget_type": "Change Order",
"budget_status": "Approved"
},
{
"id": 2,
"description": "et commodo vulputate justo in blandit",
"project_id": 78,
"budget_type": "Original",
"budget_status": "Lost"
}
]
}