Trying to wrap properties of activatedItems and quarterItems into one object i.e., modules.
{
"isExternalVisitor": false,
"isAdmin": true,
"modules": [
{
"moduleId": "4c4fd9c9",
"code": "GOT-Q1-1",
"siteId": "90837854",
"activatedId": "765abf85",
"flowId": "71170cf1",
"status": 3
},
{
"moduleId": "ac3511c1",
"code": "FOOD-Q3-1",
"siteId": "90837854",
"activatedId": "2263c865",
"flowId": "4b6cfed4",
"status": 3
},
{
"moduleId": "5e58d975",
"code": "FOOD12-Q3-1",
"siteId": "5826e23f",
"activatedId": "30323e25",
"flowId": "72800237",
"status": 3
},
{
"moduleId": "3f2e7c3c",
"code": "GOT31-Q1-1",
"siteId": "6010c42d",
"activatedId": "84227a10",
"flowId": "08734f4b",
"status": 3
}
],
"activatedItems": [
{
"activatedId": "765abf85",
"siteId": "90837854",
"stQuarterId": "bdea473a",
"checklistId": "b89f1512-2805-4e70-ac91-1710e9b80007"
},
{
"activatedId": "30323e25",
"siteId": "5826e23f",
"stQuarterId": "25a363f6",
"checklistId": "447c54fc-3541-45af-a96b-d49ccb46d33a"
},
{
"activatedId": "2263c865",
"siteId": "90837854",
"stQuarterId": "25a363f6",
"checklistId": "447c54fc-3541-45af-a96b-d49ccb46d33a"
},
{
"activatedId": "84227a10",
"siteId": "6010c42d",
"stQuarterId": "bdea473a",
"checklistId": "b89f1512-2805-4e70-ac91-1710e9b80007"
}
],
"quarterItems": [
{
"id": "bdea473a",
"checklistId": "b89f1512-2805-4e70-ac91-1710e9b80007",
"fullName": "GOT",
"year": "2021-01-01T00:00:00",
"quarter": "2021-Q1",
"versions": 1,
"activated": true
},
{
"id": "25a363f6",
"checklistId": "447c54fc-3541-45af-a96b-d49ccb46d33a",
"fullName": "FOOD",
"year": "2021-01-01T00:00:00",
"quarter": "2021-Q3",
"versions": 2,
"activated": true
}
]
}
This is the expected result where only one object has got all the data.
{
"isExternalVisitor": false,
"isAdmin": true,
"modules": [
{
"moduleId": "4c4fd9c9",
"code": "GOT-Q1-1",
"siteId": "90837854",
"activatedId": "765abf85",
"flowId": "71170cf1",
"status": 3,
"stQuarterId": "bdea473a",
"checklistId": "b89f1512-2805-4e70-ac91-1710e9b80007",
"fullName": "GOT",
"year": "2021-01-01T00:00:00",
"quarter": "2021-Q1",
"versions": 1,
"activated": true
},
{
"moduleId": "ac3511c1",
"code": "FOOD-Q3-1",
"siteId": "90837854",
"activatedId": "2263c865",
"flowId": "4b6cfed4",
"status": 3,
"stQuarterId": "25a363f6",
"checklistId": "447c54fc-3541-45af-a96b-d49ccb46d33a",
"fullName": "FOOD",
"year": "2021-01-01T00:00:00",
"quarter": "2021-Q3",
"versions": 2,
"activated": true
},
{
"moduleId": "5e58d975",
"code": "FOOD12-Q3-1",
"siteId": "5826e23f",
"activatedId": "30323e25",
"flowId": "72800237",
"status": 3,
"stQuarterId": "25a363f6",
"checklistId": "447c54fc-3541-45af-a96b-d49ccb46d33a",
"fullName": "FOOD",
"year": "2021-01-01T00:00:00",
"quarter": "2021-Q3",
"versions": 2,
"activated": true
},
{
"moduleId": "3f2e7c3c",
"code": "GOT31-Q1-1",
"siteId": "6010c42d",
"activatedId": "84227a10",
"flowId": "08734f4b",
"status": 3,
"stQuarterId": "bdea473a",
"checklistId": "b89f1512-2805-4e70-ac91-1710e9b80007",
"fullName": "GOT",
"year": "2021-01-01T00:00:00",
"quarter": "2021-Q1",
"versions": 1,
"activated": true
}
]
}
I tried the following and was able to merge them in one array, but however, the end result is not the same as above. Your kind help will be appreciated.
const result = {
isExternalVisitor: response.result.isExternalVisitor,
isAdmin: response.result.isAdmin
};
result.modules = response.result.modules.map((el, i) => ({
...el,
...response.result.activatedItems[i],
...response.result.quarterItems[i]
}));