|
|
@@ -24,7 +24,7 @@ class UserService
|
|
|
|
|
|
public function getAllPaginated(array $filters = [], int $perPage = 10): \Illuminate\Pagination\LengthAwarePaginator
|
|
|
{
|
|
|
- $query = User::with(['position', 'sector'])->orderBy('name', 'asc');
|
|
|
+ $query = User::with(['position', 'sector'])->withMin('accessLogs', 'accessed_at')->orderBy('name', 'asc');
|
|
|
|
|
|
if (!empty($filters['type'])) {
|
|
|
$query->where('type', $filters['type']);
|
|
|
@@ -34,6 +34,14 @@ class UserService
|
|
|
$query->where('status', $filters['status']);
|
|
|
}
|
|
|
|
|
|
+ if (!empty($filters['position_id'])) {
|
|
|
+ $query->where('position_id', $filters['position_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($filters['sector_id'])) {
|
|
|
+ $query->where('sector_id', $filters['sector_id']);
|
|
|
+ }
|
|
|
+
|
|
|
if (!empty($filters['search'])) {
|
|
|
$term = '%' . mb_strtolower($filters['search']) . '%';
|
|
|
$query->where(function ($q) use ($term) {
|
|
|
@@ -106,6 +114,18 @@ class UserService
|
|
|
return $model->fresh();
|
|
|
}
|
|
|
|
|
|
+ public function approve(int $id): ?User
|
|
|
+ {
|
|
|
+ $model = $this->findById($id);
|
|
|
+ if (!$model) return null;
|
|
|
+
|
|
|
+ $model->update([
|
|
|
+ 'status' => UserStatusEnum::ACTIVE,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $model->fresh();
|
|
|
+ }
|
|
|
+
|
|
|
public function getUserTypes(): array
|
|
|
{
|
|
|
return UserTypeEnum::toArray();
|