Make sure proper subfleets are returned as part of the user profile #848 (#849)

* Make sure proper subfleets are returned as part of the user profile #848

* Formatting
This commit is contained in:
Nabeel S
2020-09-30 12:58:45 -04:00
committed by GitHub
parent 98aa362935
commit 95a40d3565
5 changed files with 39 additions and 6 deletions

View File

@@ -89,10 +89,7 @@ class UserController extends Controller
*/
public function get($id)
{
$user = $this->userRepo
->with(['airline', 'bids', 'rank'])
->find($id);
$user = $this->userSvc->getUser($id);
return new UserResource($user);
}

View File

@@ -31,6 +31,7 @@ class User extends Resource
$res['airline'] = Airline::make($this->whenLoaded('airline'));
$res['bids'] = UserBid::collection($this->whenLoaded('bids'));
$res['rank'] = Rank::make($this->whenLoaded('rank'));
$res['subfleets'] = Subfleet::make($this->whenLoaded('subfleets'));
return $res;
}

View File

@@ -54,6 +54,26 @@ class UserService extends Service
$this->userRepo = $userRepo;
}
/**
* Find the user and return them with all of the data properly attached
*
* @param $user_id
*
* @return User
*/
public function getUser($user_id): User
{
$user = $this->userRepo
->with(['airline', 'bids', 'rank'])
->find($user_id);
// Load the proper subfleets to the rank
$user->rank->subfleets = $this->getAllowableSubfleets($user);
$user->subfleets = $user->rank->subfleets;
return $user;
}
/**
* Register a pilot. Also attaches the initial roles
* required, and then triggers the UserRegistered event