authorizeAbility($request, 'appointments.view'); $owner = $this->ownerRef($request); $organization = $this->organization($request); $items = QueueAppointment::owned($owner) ->where('organization_id', $organization->id) ->orderBy('scheduled_at') ->paginate(50); return response()->json(['data' => $items]); } public function store(Request $request): JsonResponse { $this->authorizeAbility($request, 'appointments.manage'); $owner = $this->ownerRef($request); $organization = $this->organization($request); $validated = $request->validate([ 'branch_id' => ['required', 'exists:queue_branches,id'], 'service_queue_id' => ['nullable', 'exists:queue_service_queues,id'], 'customer_name' => ['required', 'string', 'max:255'], 'customer_phone' => ['nullable', 'string', 'max:50'], 'customer_email' => ['nullable', 'email', 'max:255'], 'scheduled_at' => ['required', 'date'], ]); $appointment = QueueAppointment::create([ 'owner_ref' => $owner, 'organization_id' => $organization->id, ...$validated, 'status' => 'scheduled', 'reference' => 'APT-'.Str::upper(Str::random(6)), ]); AuditLogger::record($owner, 'appointment.created', $organization->id, $owner, QueueAppointment::class, $appointment->id); return response()->json(['data' => $appointment], 201); } public function checkIn(Request $request, QueueAppointment $appointment): JsonResponse { $this->authorizeAbility($request, 'appointments.manage'); $this->authorizeOwner($request, $appointment); $ticket = app(AppointmentService::class)->checkIn($appointment, $this->ownerRef($request)); return response()->json(['data' => \App\Services\Qms\TicketPresenter::toArray($ticket)]); } }