I would move the case into its own method on your Team model.
class Team
def tree(type)
...
end
end
Then in your controller you could just have the following
if @team = fetch_team
@output = @team.tree(params[:tree])
render json: @output
else
render json: {message: "team: '#{params[:id]}' not found"}, status: 404
end