I want to remove the key team_id from the following response:
{
"id": 14,
"name": "Angel Stadium of Anaheim",
"opened": "1966-04-19T00:00:00.000Z",
"capacity": 45517,
"location": "Anaheim, California",
"team_id": "95cbbe2a",
"team": {
"id": "95cbbe2a",
"name": "Los Angeles Angels",
"established_in": 1961,
"league": "American League",
"division": "West Division",
"logo": "https://upload.wikimedia.org/wikipedia/commons/7/79/Los_Angeles_Angels_of_Anaheim_Insignia.svg",
"number_of_titles":1
}
}
The code I'm using right now gets all the data from the venues, at first I need all of them but at the final response I'd like to omit the the team_id key:
const venues = await connection(VENUE_TABLE)
.limit(LIMIT_PER_PAGE)
.offset((page - 1) * LIMIT_PER_PAGE)
.select('*')
.orderBy('name');
const venuesWithTeam = await venues.reduce(
(promise, element) =>
promise.then(async (result) =>
result.concat({
...element,
team: await connection('team')
.where('id', element.team_id)
.select('*')
.first(),
})
),
Promise.resolve([])
);
The desired behavior would be:
{
"id": 14,
"name": "Angel Stadium of Anaheim",
"opened": "1966-04-19T00:00:00.000Z",
"capacity": 45517,
"location": "Anaheim, California",
"team": {
"id": "95cbbe2a",
"name": "Los Angeles Angels",
"established_in": 1961,
"league": "American League",
"division": "West Division",
"logo": "https://upload.wikimedia.org/wikipedia/commons/7/79/Los_Angeles_Angels_of_Anaheim_Insignia.svg",
"number_of_titles":1
}
}
What can I do to make this happen?