我目前正在开发一个端点,我想从4个不同的表中返回一个对象。我从sequelize中获得每个表的JSON格式记录。我有一个位置、服务、员工和租户。我如何将它们合并为一个嵌套的对象。例如:我从sequelize工作人员那里得到的数据是:
{
"id": 2,
"profession": "Dentist",
"note": "Good Man",
"holidays": "Saturday",
"specialDays": null,
"createdAt": "2023-01-27T14:23:52.000Z",
"updatedAt": "2023-01-27T14:23:52.000Z",
}
所有其他数据都是类似的格式,但我想合并它们,返回类似于以下内容的结果:
{ staff:{
"id": 2,
"profession": "Dentist",
"note": "Good Man",
"holidays": "Saturday",
"specialDays": null,
"createdAt": "2023-01-27T14:23:52.000Z",
"updatedAt": "2023-01-27T14:23:52.000Z",},
location:{
"id": 1,
"name": "Branch 1",
"address": "37 Automatic Handling",
"description": "This is our main branch",
"latitude": "564233",
"longtitude": "4441256",
"visible": true,
"createdAt": "2023-01-27T14:05:37.000Z",
"updatedAt": "2023-01-27T14:05:37.000Z",
}
}
2条答案
按热度按时间4uqofj5v1#
你自己做一个东西
ltskdhd12#
这个应该可以