I have an array of objects containing employeeProjectId which might be same. So what I am looking for is that if there is more than one same employeeProjectId then merge the results into one object with having projectRoles in the form of array. Response is given below for reference. Thankyou :)
{
"code": 200,
"success": true,
"message": "Successfully completed",
"data": [
{
"employeeProjectId": 1,
"projectRoleId": 1,
"employee_project": {
"id": 1,
"status": true,
"type": "backup",
"startDate": "2018-06-28T07:20:36.000Z",
"endDate": "2018-06-29T07:20:39.000Z",
"allocation": 100,
"employeeId": 326,
"projectId": 35,
"employee": {
"firstName": "Asad",
"lastName": "Marfani"
},
"project": {
"name": "RTA"
}
},
"project_role": {
"id": 1,
"role": "front_end_ios"
}
},
{
"employeeProjectId": 1,
"projectRoleId": 2,
"employee_project": {
"id": 1,
"status": true,
"type": "backup",
"startDate": "2018-06-28T07:20:36.000Z",
"endDate": "2018-06-29T07:20:39.000Z",
"allocation": 100,
"employeeId": 326,
"projectId": 35,
"employee": {
"firstName": "Asad",
"lastName": "Marfani"
},
"project": {
"name": "RTA"
}
},
"project_role": {
"id": 2,
"role": "Front End - Android"
}
},
{
"employeeProjectId": 3,
"projectRoleId": 1,
"employee_project": {
"id": 3,
"status": true,
"type": "backup",
"startDate": "2018-06-28T07:47:19.000Z",
"endDate": "2018-06-29T07:47:22.000Z",
"allocation": 50,
"employeeId": 16,
"projectId": 35,
"employee": {
"firstName": "Nosheen",
"lastName": "Sikandar"
},
"project": {
"name": "RTA"
}
},
"project_role": {
"id": 1,
"role": "front_end_ios"
}
},
{
"employeeProjectId": 3,
"projectRoleId": 3,
"employee_project": {
"id": 3,
"status": true,
"type": "backup",
"startDate": "2018-06-28T07:47:19.000Z",
"endDate": "2018-06-29T07:47:22.000Z",
"allocation": 50,
"employeeId": 16,
"projectId": 35,
"employee": {
"firstName": "Nosheen",
"lastName": "Sikandar"
},
"project": {
"name": "RTA"
}
},
"project_role": {
"id": 3,
"role": "Front End - Web"
}
}
]}
I want it like this :
{
"code": 200,
"success": true,
"message": "Successfully completed",
"data": [
{
"employeeProjectId": 1,
"employee_project": {
"id": 1,
"status": true,
"type": "backup",
"startDate": "2018-06-28T07:20:36.000Z",
"endDate": "2018-06-29T07:20:39.000Z",
"allocation": 100,
"employeeId": 326,
"projectId": 35,
"employee": {
"firstName": "Asad",
"lastName": "Marfani"
},
"project": {
"name": "RTA"
}
},
"project_role": [
{
"id": 1,
"role": "front_end_ios",
},
{
"id": 2,
"role": "front_end_web"
}
]
}
]}
projectRoleIdnot also be an an array and I think your result does not reflect what you like it to be, there are 2 project_role objects that are the same (same id and role).