The problem of merging javascript objects

in the following objects:

var prd = {
    "id": 1,
    "department_id": 42,
    "products": [{
            "id": 12,
            "name": "49da",
            "grouped_addons": [{
                "addons": [{
                        "id": "0_0_40",
                        "name": "rice",
                        "qty": 0,
                        "unit_price": "5.00"
                    },
                    {
                        "id": "0_0_41",
                        "name": "what",
                        "qty": 1,
                        "unit_price": "15.00"
                    }
                ]
            }]
        },
        {
            "id": 12,
            "name": "49da",
            "grouped_addons": [{
                "addons": [{
                    "id": "0_0_40",
                    "name": "rice",
                    "qty": 0,
                    "unit_price": "5.00"
                }, {
                    "id": "0_0_41",
                    "name": "what",
                    "qty": 1,
                    "unit_price": "15.00"
                }]
            }]
        },
        {
            "id": 42,
            "name": "345dd",
            "grouped_addons": [{
                "addons": [{
                    "id": "0_0_42",
                    "name": "rice",
                    "qty": 0,
                    "unit_price": "5.00"
                }, {
                    "id": "0_0_43",
                    "name": "what",
                    "qty": 1,
                    "unit_price": "15.00"
                }]
            }]
        },
        {
            "id": 48,
            "name": "33ffg",
            "grouped_addons": [{
                "addons": [{
                    "id": "0_0_44",
                    "name": "rice",
                    "qty": 0,
                    "unit_price": "5.00"
                }, {
                    "id": "0_0_45",
                    "name": "what",
                    "qty": 1,
                    "unit_price": "15.00"
                }]
            }]
        },
        {
            "id": 48,
            "name": "33ffg",
            "grouped_addons": [{
                "addons": [{
                    "id": "0_0_44",
                    "name": "rice",
                    "qty": 1,
                    "unit_price": "5.00"
                }, {
                    "id": "0_0_45",
                    "name": "what",
                    "qty": 3,
                    "unit_price": "15.00"
                }]
            }]
        }
    ]
}

I want to add and merge the qty in the products in prd and the qty in the grouped_addons of the same object in id, and the final result is as follows:

var prd = {
    "id": 1,
    "department_id": 42,
    "products": [{
            "id": 12,
            "name": "49da",
            "grouped_addons": [{
                "addons": [{
                        "id": "0_0_40",
                        "name": "rice",
                        "qty": 0,
                        "unit_price": "5.00"
                    },
                    {
                        "id": "0_0_41",
                        "name": "what",
                        "qty": 2,
                        "unit_price": "15.00"
                    }
                ]
            }]
        },
        {
            "id": 42,
            "name": "345dd",
            "grouped_addons": [{
                "addons": [{
                    "id": "0_0_42",
                    "name": "rice",
                    "qty": 0,
                    "unit_price": "5.00"
                }, {
                    "id": "0_0_43",
                    "name": "what",
                    "qty": 1,
                    "unit_price": "15.00"
                }]
            }]
        },
        {
            "id": 48,
            "name": "33ffg",
            "grouped_addons": [{
                "addons": [{
                    "id": "0_0_44",
                    "name": "rice",
                    "qty": 1,
                    "unit_price": "5.00"
                }, {
                    "id": "0_0_45",
                    "name": "what",
                    "qty": 4,
                    "unit_price": "15.00"
                }]
            }]
        }
    ]
}
Mar.02,2021

var mp = prd.products.reduce((obj, item) => {
        if (!obj[item.id]) {
            obj[item.id] = [item]
        } else {
            obj[item.id].push(item)
        }
        return obj
    }, {})
    prd.products = Object.keys(mp).map(id => {
        return mp[id].reduce((state, item) => {
            item.grouped_addons[0].addons.forEach(addon => {
                var item = state.grouped_addons[0].addons.find(a => a.id === addon.id)
                item.qty += addon.qty
            })
            return state
        })
    })
    console.log(prd)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2241e-2b5e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2241e-2b5e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?