Code Optimization on data manipulation

there are many service stations under the city that need the data of linkage effect
all the servers are returned to me. My code is as follows, how to optimize

export const dealDistribution = (data) => {
  const treeData = []
  data.forEach(item => {
    const isExit = treeData.find(treeItem => treeItem.cityCode === item.cityCode)
    if (!isExit) {
      treeData.push({
        cityCode: item.cityCode,
        cityName: item.cityName,
        pickhouseList: []
      })
    }
  })
  treeData.map(treeItem => {
    data.map(dataItem => {
      if (treeItem.cityCode === dataItem.cityCode) {
        treeItem.pickhouseList.push({
          pickhouseId: dataItem.id,
          pickhouseName: dataItem.name
        })
      }
    })
  })
  return treeData
}
Apr.26,2022

I think it's the problem of database design

1, city data

[
    {
        "cityName": xxx,
        "cityCode": xxx,
    },
    {
        "cityName": xxx,
        "cityCode": xxx,
    },
]

Select the city, and then request the subordinate service station from the server.

2. Data of service stations under the city

the server looks for subordinate service stations according to cityCode .

{
     "cityName": xxx,
     "cityCode": xxx,
     "sub": [
            {
                "name": xxx,
                "code": xxx
            }
     ]
}
Menu