Add pilot ID change fields to the admin screen

This commit is contained in:
Nabeel Shahzad
2019-07-17 09:48:20 -04:00
parent 337fe5cfaa
commit 567ff91de0
7 changed files with 38 additions and 8 deletions

View File

@@ -108,6 +108,11 @@ class UserService extends Service
return $user;
}
public function isPilotIdAlreadyUsed(int $pilot_id): bool
{
return User::where('pilot_id', '=', $pilot_id)->exists();
}
/**
* Change a user's pilot ID
*
@@ -120,7 +125,11 @@ class UserService extends Service
*/
public function changePilotId(User $user, int $pilot_id): User
{
if (User::where('pilot_id', '=', $pilot_id)->exists()) {
if ($user->pilot_id === $pilot_id) {
return $user;
}
if ($this->isPilotIdAlreadyUsed($pilot_id)) {
Log::error('User with id '.$pilot_id.' already exists');
throw new UserPilotIdExists();