I am currently developing an endpoint where I want to return one object from 4 different tables. I get the record of each table in JSON format from sequelize. I have a location, service, staff, and Tenant. How can I merge them into one object but nested.
For example:
The data I get from sequelize for 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",
}
All other data are in a similar format. But I want to merge them to return something like:
{ 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
Answers
Just make an object yourself
This should work