I'm in the process of creating an endpoint where I need to combine data from four different tables into one nested object. Each table record is retrieved in JSON format using sequelize - they include information on location, service, staff, and tenant. How can I merge these records into a single nested object? For example: The data obtained 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 follows a similar format but I aim to merge them to create a combined output like this:
{
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",
"longitude": "4441256",
"visible": true,
"createdAt": "2023-01-27T14:05:37.000Z",
"updatedAt": "2023-01-27T14:05:37.000Z",
}
}