Files
crewli/api/app/Http/Resources/Api/V1/ShiftAssignmentResource.php
bert.hausmans 3e292567c3 feat: smart re-assignment with cancellation source tracking
Add cancelled_by, cancellation_source (organiser|volunteer|system), and
cancelled_at columns to shift_assignments. Cancel flow now records who
cancelled and why. Assign flow reactivates existing cancelled/rejected
records instead of creating duplicates, preventing UNIQUE constraint
violations. Assignable-persons endpoint returns previous_assignment data
for contextual UI indicators. Frontend shows cancellation source labels,
previous assignment history in assign dialog, and "Opnieuw toewijzen"
buttons with volunteer-cancelled confirmation dialogs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 21:50:24 +02:00

42 lines
1.6 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 ShiftAssignmentResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'shift_id' => $this->shift_id,
'person_id' => $this->person_id,
'time_slot_id' => $this->time_slot_id,
'status' => $this->status->value,
'auto_approved' => $this->auto_approved,
'assigned_by' => $this->assigned_by,
'assigned_at' => $this->assigned_at?->toIso8601String(),
'approved_by' => $this->approved_by,
'approved_at' => $this->approved_at?->toIso8601String(),
'rejection_reason' => $this->rejection_reason,
'cancelled_by' => $this->cancelled_by,
'cancellation_source' => $this->cancellation_source?->value,
'cancelled_at' => $this->cancelled_at?->toIso8601String(),
'hours_expected' => $this->hours_expected,
'hours_completed' => $this->hours_completed,
'checked_in_at' => $this->checked_in_at?->toIso8601String(),
'checked_out_at' => $this->checked_out_at?->toIso8601String(),
'is_cancellable' => $this->isCancellable(),
'is_approvable' => $this->isApprovable(),
'created_at' => $this->created_at?->toIso8601String(),
'person' => new PersonResource($this->whenLoaded('person')),
'shift' => new ShiftResource($this->whenLoaded('shift')),
];
}
}