|
|
@@ -2,8 +2,6 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
-use App\Enums\UserTypeEnum;
|
|
|
-use App\Models\Unit;
|
|
|
use App\Models\UnitUser;
|
|
|
use App\Models\User;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
@@ -20,7 +18,7 @@ public function authUser(): ?User
|
|
|
|
|
|
public function getAll(): Collection
|
|
|
{
|
|
|
- return User::with(['state', 'units'])->orderBy('name')->get();
|
|
|
+ return User::with(['state', 'units', 'userType'])->orderBy('name')->get();
|
|
|
}
|
|
|
|
|
|
public function getAllByUnit(): Collection
|
|
|
@@ -28,10 +26,10 @@ public function getAllByUnit(): Collection
|
|
|
$unitId = Auth::user()->units->first()?->id;
|
|
|
|
|
|
if (!$unitId) {
|
|
|
- return collect();
|
|
|
+ return User::with(['state', 'units', 'userType'])->whereNull('id')->get();
|
|
|
}
|
|
|
|
|
|
- return User::with(['state', 'units'])
|
|
|
+ return User::with(['state', 'units', 'userType'])
|
|
|
->whereHas('units', fn($q) => $q->where('units.id', $unitId))
|
|
|
->orderBy('name')
|
|
|
->get();
|
|
|
@@ -39,7 +37,7 @@ public function getAllByUnit(): Collection
|
|
|
|
|
|
public function findById(int $id): ?User
|
|
|
{
|
|
|
- return User::with(['state', 'units'])->find($id);
|
|
|
+ return User::with(['state', 'units', 'userType'])->find($id);
|
|
|
}
|
|
|
|
|
|
public function create(array $data): User
|
|
|
@@ -97,9 +95,9 @@ public function delete(int $id): bool
|
|
|
return $model->delete();
|
|
|
}
|
|
|
|
|
|
- public function getUserTypes(): array
|
|
|
+ public function getUserTypes(): \Illuminate\Database\Eloquent\Collection
|
|
|
{
|
|
|
- return UserTypeEnum::toArray();
|
|
|
+ return \App\Models\UserType::orderBy('label')->get();
|
|
|
}
|
|
|
|
|
|
private function handleAvatar(array $data, ?string $oldAvatarPath = null): array
|