Files
crewli/api/app/Http/Resources/Api/V1/ShiftResource.php
bert.hausmans 9acb27af3a feat: fase 2 backend — crowd types, persons, sections, shifts, invite flow
- Crowd Types + Persons CRUD (73 tests)
- Festival Sections + Time Slots + Shifts CRUD met assign/claim flow (84 tests)
- Invite Flow + Member Management met InvitationService (109 tests)
- Schema v1.6 migraties volledig uitgevoerd
- DevSeeder bijgewerkt met crowd types voor testorganisatie
2026-04-08 01:34:46 +02:00

72 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Resources\Api\V1;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
final class ShiftResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'festival_section_id' => $this->festival_section_id,
'time_slot_id' => $this->time_slot_id,
'location_id' => $this->location_id,
'title' => $this->title,
'description' => $this->description,
'instructions' => $this->instructions,
'coordinator_notes' => $this->when(
$this->shouldShowCoordinatorNotes($request),
$this->coordinator_notes,
),
'slots_total' => $this->slots_total,
'slots_open_for_claiming' => $this->slots_open_for_claiming,
'is_lead_role' => $this->is_lead_role,
'report_time' => $this->report_time,
'actual_start_time' => $this->actual_start_time,
'actual_end_time' => $this->actual_end_time,
'allow_overlap' => $this->allow_overlap,
'status' => $this->status,
'filled_slots' => $this->filled_slots,
'fill_rate' => $this->fill_rate,
'effective_start_time' => $this->effective_start_time,
'effective_end_time' => $this->effective_end_time,
'created_at' => $this->created_at->toIso8601String(),
'time_slot' => new TimeSlotResource($this->whenLoaded('timeSlot')),
'location' => new LocationResource($this->whenLoaded('location')),
'festival_section' => new FestivalSectionResource($this->whenLoaded('festivalSection')),
];
}
private function shouldShowCoordinatorNotes(Request $request): bool
{
$user = $request->user();
if (! $user) {
return false;
}
if ($user->hasRole('super_admin')) {
return true;
}
$shift = $this->resource;
$event = $shift->festivalSection?->event;
if (! $event) {
return false;
}
return $event->organisation->users()
->where('user_id', $user->id)
->wherePivot('role', 'org_admin')
->exists()
|| $event->users()
->where('user_id', $user->id)
->wherePivot('role', 'event_manager')
->exists();
}
}