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
This commit is contained in:
38
api/app/Models/Company.php
Normal file
38
api/app/Models/Company.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
final class Company extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'organisation_id',
|
||||
'name',
|
||||
'type',
|
||||
'contact_name',
|
||||
'contact_email',
|
||||
'contact_phone',
|
||||
];
|
||||
|
||||
public function organisation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
|
||||
public function persons(): HasMany
|
||||
{
|
||||
return $this->hasMany(Person::class);
|
||||
}
|
||||
}
|
||||
56
api/app/Models/CrowdList.php
Normal file
56
api/app/Models/CrowdList.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
final class CrowdList extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = [
|
||||
'event_id',
|
||||
'crowd_type_id',
|
||||
'name',
|
||||
'type',
|
||||
'recipient_company_id',
|
||||
'auto_approve',
|
||||
'max_persons',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'auto_approve' => 'boolean',
|
||||
'max_persons' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
|
||||
public function crowdType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CrowdType::class);
|
||||
}
|
||||
|
||||
public function recipientCompany(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class, 'recipient_company_id');
|
||||
}
|
||||
|
||||
public function persons(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Person::class, 'crowd_list_persons')
|
||||
->withPivot('added_at', 'added_by_user_id');
|
||||
}
|
||||
}
|
||||
43
api/app/Models/CrowdType.php
Normal file
43
api/app/Models/CrowdType.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
final class CrowdType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = [
|
||||
'organisation_id',
|
||||
'name',
|
||||
'system_type',
|
||||
'color',
|
||||
'icon',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function organisation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
|
||||
public function persons(): HasMany
|
||||
{
|
||||
return $this->hasMany(Person::class);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,31 @@ final class Event extends Model
|
||||
return $this->hasMany(UserInvitation::class);
|
||||
}
|
||||
|
||||
public function locations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Location::class);
|
||||
}
|
||||
|
||||
public function festivalSections(): HasMany
|
||||
{
|
||||
return $this->hasMany(FestivalSection::class);
|
||||
}
|
||||
|
||||
public function timeSlots(): HasMany
|
||||
{
|
||||
return $this->hasMany(TimeSlot::class);
|
||||
}
|
||||
|
||||
public function persons(): HasMany
|
||||
{
|
||||
return $this->hasMany(Person::class);
|
||||
}
|
||||
|
||||
public function crowdLists(): HasMany
|
||||
{
|
||||
return $this->hasMany(CrowdList::class);
|
||||
}
|
||||
|
||||
public function scopeDraft(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'draft');
|
||||
|
||||
61
api/app/Models/FestivalSection.php
Normal file
61
api/app/Models/FestivalSection.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
final class FestivalSection extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'event_id',
|
||||
'name',
|
||||
'type',
|
||||
'sort_order',
|
||||
'crew_need',
|
||||
'crew_auto_accepts',
|
||||
'crew_invited_to_events',
|
||||
'added_to_timeline',
|
||||
'responder_self_checkin',
|
||||
'crew_accreditation_level',
|
||||
'public_form_accreditation_level',
|
||||
'timed_accreditations',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'crew_auto_accepts' => 'boolean',
|
||||
'crew_invited_to_events' => 'boolean',
|
||||
'added_to_timeline' => 'boolean',
|
||||
'responder_self_checkin' => 'boolean',
|
||||
'timed_accreditations' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
|
||||
public function shifts(): HasMany
|
||||
{
|
||||
return $this->hasMany(Shift::class);
|
||||
}
|
||||
|
||||
public function scopeOrdered(Builder $query): Builder
|
||||
{
|
||||
return $query->orderBy('sort_order');
|
||||
}
|
||||
}
|
||||
31
api/app/Models/Location.php
Normal file
31
api/app/Models/Location.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
final class Location extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = [
|
||||
'event_id',
|
||||
'name',
|
||||
'address',
|
||||
'lat',
|
||||
'lng',
|
||||
'description',
|
||||
'access_instructions',
|
||||
];
|
||||
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,14 @@ final class Organisation extends Model
|
||||
{
|
||||
return $this->hasMany(UserInvitation::class);
|
||||
}
|
||||
|
||||
public function crowdTypes(): HasMany
|
||||
{
|
||||
return $this->hasMany(CrowdType::class);
|
||||
}
|
||||
|
||||
public function companies(): HasMany
|
||||
{
|
||||
return $this->hasMany(Company::class);
|
||||
}
|
||||
}
|
||||
|
||||
91
api/app/Models/Person.php
Normal file
91
api/app/Models/Person.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
final class Person extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'persons';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'event_id',
|
||||
'crowd_type_id',
|
||||
'company_id',
|
||||
'name',
|
||||
'email',
|
||||
'phone',
|
||||
'status',
|
||||
'is_blacklisted',
|
||||
'admin_notes',
|
||||
'custom_fields',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_blacklisted' => 'boolean',
|
||||
'custom_fields' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
|
||||
public function crowdType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CrowdType::class);
|
||||
}
|
||||
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function crowdLists(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(CrowdList::class, 'crowd_list_persons')
|
||||
->withPivot('added_at', 'added_by_user_id');
|
||||
}
|
||||
|
||||
public function shiftAssignments(): HasMany
|
||||
{
|
||||
return $this->hasMany(ShiftAssignment::class);
|
||||
}
|
||||
|
||||
public function scopeApproved(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'approved');
|
||||
}
|
||||
|
||||
public function scopePending(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'pending');
|
||||
}
|
||||
|
||||
public function scopeForCrowdType(Builder $query, string $type): Builder
|
||||
{
|
||||
return $query->whereHas('crowdType', fn (Builder $q) => $q->where('system_type', $type));
|
||||
}
|
||||
}
|
||||
124
api/app/Models/Shift.php
Normal file
124
api/app/Models/Shift.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
final class Shift extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'festival_section_id',
|
||||
'time_slot_id',
|
||||
'location_id',
|
||||
'title',
|
||||
'description',
|
||||
'instructions',
|
||||
'coordinator_notes',
|
||||
'slots_total',
|
||||
'slots_open_for_claiming',
|
||||
'is_lead_role',
|
||||
'report_time',
|
||||
'actual_start_time',
|
||||
'actual_end_time',
|
||||
'end_date',
|
||||
'allow_overlap',
|
||||
'assigned_crew_id',
|
||||
'events_during_shift',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_lead_role' => 'boolean',
|
||||
'allow_overlap' => 'boolean',
|
||||
'events_during_shift' => 'array',
|
||||
'slots_total' => 'integer',
|
||||
'slots_open_for_claiming' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function festivalSection(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(FestivalSection::class);
|
||||
}
|
||||
|
||||
public function timeSlot(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TimeSlot::class);
|
||||
}
|
||||
|
||||
public function location(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Location::class);
|
||||
}
|
||||
|
||||
public function assignedCrew(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assigned_crew_id');
|
||||
}
|
||||
|
||||
public function shiftAssignments(): HasMany
|
||||
{
|
||||
return $this->hasMany(ShiftAssignment::class);
|
||||
}
|
||||
|
||||
public function waitlist(): HasMany
|
||||
{
|
||||
return $this->hasMany(ShiftWaitlist::class);
|
||||
}
|
||||
|
||||
protected function effectiveStartTime(): Attribute
|
||||
{
|
||||
return Attribute::get(fn () => $this->actual_start_time ?? $this->timeSlot?->start_time);
|
||||
}
|
||||
|
||||
protected function effectiveEndTime(): Attribute
|
||||
{
|
||||
return Attribute::get(fn () => $this->actual_end_time ?? $this->timeSlot?->end_time);
|
||||
}
|
||||
|
||||
protected function filledSlots(): Attribute
|
||||
{
|
||||
return Attribute::get(fn () => $this->shiftAssignments()->where('status', 'approved')->count());
|
||||
}
|
||||
|
||||
protected function fillRate(): Attribute
|
||||
{
|
||||
return Attribute::get(function () {
|
||||
if ($this->slots_total === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return round($this->filled_slots / $this->slots_total, 2);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeOpen(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'open');
|
||||
}
|
||||
|
||||
public function scopeDraft(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'draft');
|
||||
}
|
||||
|
||||
public function scopeFull(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'full');
|
||||
}
|
||||
}
|
||||
61
api/app/Models/ShiftAssignment.php
Normal file
61
api/app/Models/ShiftAssignment.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
final class ShiftAssignment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'shift_id',
|
||||
'person_id',
|
||||
'time_slot_id',
|
||||
'status',
|
||||
'auto_approved',
|
||||
'assigned_by',
|
||||
'assigned_at',
|
||||
'approved_by',
|
||||
'approved_at',
|
||||
'rejection_reason',
|
||||
'hours_expected',
|
||||
'hours_completed',
|
||||
'checked_in_at',
|
||||
'checked_out_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'auto_approved' => 'boolean',
|
||||
'assigned_at' => 'datetime',
|
||||
'approved_at' => 'datetime',
|
||||
'checked_in_at' => 'datetime',
|
||||
'checked_out_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function shift(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Shift::class);
|
||||
}
|
||||
|
||||
public function person(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Person::class);
|
||||
}
|
||||
|
||||
public function timeSlot(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TimeSlot::class);
|
||||
}
|
||||
}
|
||||
46
api/app/Models/ShiftWaitlist.php
Normal file
46
api/app/Models/ShiftWaitlist.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
final class ShiftWaitlist extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $table = 'shift_waitlist';
|
||||
|
||||
protected $fillable = [
|
||||
'shift_id',
|
||||
'person_id',
|
||||
'position',
|
||||
'added_at',
|
||||
'notified_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'added_at' => 'datetime',
|
||||
'notified_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function shift(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Shift::class);
|
||||
}
|
||||
|
||||
public function person(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Person::class);
|
||||
}
|
||||
}
|
||||
57
api/app/Models/TimeSlot.php
Normal file
57
api/app/Models/TimeSlot.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
final class TimeSlot extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = [
|
||||
'event_id',
|
||||
'name',
|
||||
'person_type',
|
||||
'date',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'duration_hours',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'date' => 'date',
|
||||
'person_type' => 'string',
|
||||
];
|
||||
}
|
||||
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
|
||||
public function shifts(): HasMany
|
||||
{
|
||||
return $this->hasMany(Shift::class);
|
||||
}
|
||||
|
||||
public function scopeForType(Builder $query, string $type): Builder
|
||||
{
|
||||
return $query->where('person_type', $type);
|
||||
}
|
||||
|
||||
public function scopeForDate(Builder $query, Carbon $date): Builder
|
||||
{
|
||||
return $query->whereDate('date', $date);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,26 @@ final class UserInvitation extends Model
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
|
||||
public function isExpired(): bool
|
||||
{
|
||||
return $this->expires_at->isPast();
|
||||
}
|
||||
|
||||
public function isPending(): bool
|
||||
{
|
||||
return $this->status === 'pending';
|
||||
}
|
||||
|
||||
public function markAsAccepted(): void
|
||||
{
|
||||
$this->update(['status' => 'accepted']);
|
||||
}
|
||||
|
||||
public function markAsExpired(): void
|
||||
{
|
||||
$this->update(['status' => 'expired']);
|
||||
}
|
||||
|
||||
public function scopePending(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'pending');
|
||||
|
||||
Reference in New Issue
Block a user