refactor: streamline user query methods for improved readability and maintainability
This commit is contained in:
parent
a8a7ed4c69
commit
0a688f1028
@ -11,8 +11,8 @@ class EmployeeService
|
||||
{
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return User::select('id', 'email', 'username', 'is_active')
|
||||
->whereHas('employee')
|
||||
return User::select(['id', 'email', 'username', 'is_active'])
|
||||
->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner')))
|
||||
->with([
|
||||
'userProfile' => fn($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'),
|
||||
'employee' => fn($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
|
||||
@ -28,8 +28,8 @@ public function getAll(array $filters = []): Collection
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
return User::query()
|
||||
->select('id', 'email', 'username', 'is_active')
|
||||
->whereHas('employee')
|
||||
->select(['id', 'email', 'username', 'is_active'])
|
||||
->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner')))
|
||||
->with([
|
||||
'userProfile' => fn($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'),
|
||||
'employee' => fn($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
|
||||
@ -43,11 +43,6 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getById(int $id): User
|
||||
{
|
||||
return User::with(['userProfile', 'employee'])->findOrFail($id);
|
||||
}
|
||||
|
||||
public function create(array $data): User
|
||||
{
|
||||
return DB::transaction(function () use ($data) {
|
||||
|
||||
@ -111,12 +111,15 @@ export function createEmployeeColumns(
|
||||
header: () => <span>Status</span>,
|
||||
cell: ({ row }) => {
|
||||
const employee = row.original;
|
||||
const status = employee.employee?.employment_status;
|
||||
|
||||
if (!status) {
|
||||
return <span>-</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<span className="inline-flex items-center rounded-md bg-muted px-2 py-1 text-xs font-medium">
|
||||
{getEmploymentStatusLabel(
|
||||
employee.employee?.employment_status ?? '',
|
||||
)}
|
||||
{getEmploymentStatusLabel(status)}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user