function fetchUser(username) {
return fetch(`/api/users/${username}`)
.then((resp) => resp.json())
.then((userJSON) => {
if (userJSON.team !== undefined) {
return fetch(`/api/teams/${userJSON.team}`)
.then((resp) => resp.json())
.then((teamJSON) => {
return {
user: userJSON,
team: teamJSON,
};
});
}
return {
user: userJSON,
team: null,
};
})
.catch((err) => {
console.error('Something went wrong', err);
});
}