I'm seeking suggestions on how to achieve this task. The getAllData function returns an array of objects, and I need to iterate through each object resulting from getAllData and extract the id of objects with Type-A. Subsequently, I aim to use each id to query getDealDetails based on the Id.
If there is a matching id in getDealDetails and it has a result, I want to retrieve the TypeValues summary value from the getDealDetails result and add a new key-value pair to the res items obtained from getAllData. The new key will be "dataValue:" and the value will be the data fetched from TypeValues summary.
The final result should resemble the sample object provided below. For instance, if there is a match with the id 248, then append the specified dataValue.
Thank you for any assistance and insights.
[
{
"id": 248,
"name": "248-A",
"Type": "Type-A",
"fileName": null,
"serverFileName": null,
"size": null,
"absoluteUri": null,
"sentTo": null,
"dataValue": "Summary Data"
},
{
"id": 249,
"name": "249-A",
"Type": "Type-A",
"fileName": null,
"serverFileName": null,
"size": null,
"absoluteUri": null,
"sentTo": null
},
{
"id": 243,
"name": "243-Z",
"Type": "Type-Z",
"fileName": null,
"serverFileName": null,
"size": null,
"absoluteUri": null,
"sentTo": null
},
]
Here's the code snippet fetching data and the res items:
private getAllData() {
this.searchInput = '';
const status = 'Draft'
this.isLoading = true;
this.dealService
.getAllData(
status,
this.accountId,
this.transaction.id,
this.table.pageIndex + 1,
this.table.pageSize,
this.searchInput,
this.table.sortParams,
this.table.sortDirs
)
.pipe(finalize(() => (this.isLoading = false)))
.subscribe((res) => {
console.log("ress " , res.items)
this.getDealDetails(res.items.id);
}, (err) => this.notificationService.showError(err)
);
}
Below are sample result items obtained from getAllData:
[
{
"id": 248,
"name": "248-A",
"Type": "Type-A",
"fileName": null,
"serverFileName": null,
"size": null,
"absoluteUri": null,
"sentTo": null
},
{
"id": 249,
"name": "249-A",
"Type": "Type-A",
"fileName": null,
"serverFileName": null,
"size": null,
"absoluteUri": null,
"sentTo": null
},
{
"id": 243,
"name": "243-Z",
"Type": "Type-Z",
"fileName": null,
"serverFileName": null,
"size": null,
"absoluteUri": null,
"sentTo": null
},
]
Code snippet for fetching details:
getDetails(Id: number) {
this.service.getDetails(Id)
.subscribe(
res =>{
console.log("res.data;" , res.data)
},
err =>{
console.log('Error getting deal details');
}
)
}
Sample result from getDetails:
{
"id": 248,
"name": "248-A",
"fileName": null,
"serverFileName": null,
"size": null,
"absoluteUri": null,
"sentTo": null,
"TypeValues": {
"id": 24,
"name": "248-A",
"summary": "Summary Data",
}
}
}