Inserting an accountId key and value into the this.membersForm.value object is the goal, while also setting the id to 0 and adding memberId: id to the this.membersForm.value.teamMembersDto object.
How can we achieve this task of inserting the accountId key and value into the object? Please refer to the expectedOutput for more clarity.
Any ideas on what might be causing the issue in the code?
#myCode
const accountId = this.data.accountId
this.membersForm.value.teamMembersDto = this.membersForm.value.teamMembersDto.map((item) => {
let id = item.id;
return {
...item,
memberId: id,
id: 0,
}
});
#original data
this.membersForm.value = {
"id": 10011,
"teamMembersDto": [
{
"id": 1,
"firstName": "Marthy",
"lastName": "Hills",
"roleDisplay": "COVP,DVP Real Estate",
"companyName": "Techmo",
"title": "COO",
},
{
"id": 2,
"firstName": "Briana",
"lastName": "Christoval",
"roleDisplay": "Architect,Construction Project Director",
"companyName": null,
"title": null,
}
]
}
#expectedOutput
{
"id": 10011,
"accountId:" 4,
"teamMembersDto": [
{
"id": 0,
"firstName": "Marthy",
"lastName": "Hills",
"roleDisplay": "COVP,DVP Real Estate",
"companyName": "Techmo",
"title": "COO",
"memberId": 1,
},
{
"id": 0,
"firstName": "Briana",
"lastName": "Christoval",
"roleDisplay": "Architect,Construction Project Director",
"companyName": null,
"title": null,
"memberId": 2,
},
]
}
___________________second question
#data
{
"id": 20018,
"name": "yoyo",
"description": "yoyoyo",
"memberCount": 2,
"accountId": 4,
"status": "Active",
"createOnString": null,
"teamMembersDto": [
{
"id": 10090,
"firstName": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82c3c6c3d1c6c3c6c2e5efe3ebeeace1edef">[email protected]</a>",
... (remaining text unchanged) ...
"fullName": "adasdas dasdas"
}
],
"teamTransactionDetailsDto": []
}
#exptectOutput
{
"id": 20018,
"name": "yoyo",
"description": "yoyoyo",
"memberCount": 2,
"accountId": 4,
"status": "Active",
"createOnString": null,
"teamMembersDto": [
{
"id": 10090,
"firstName": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6f7f2f7e5f2f7f2f6d1dbd7dfda98d5d9db">[email protected]</a>",
... (remaining text unchanged) ...
"fullName": "adasdas dasdas"
}
],
"teamTransactionDetailsDto": []
}