refactor: align codebase with EventCrew domain and trim legacy band stack
- Update API: events, users, policies, routes, resources, migrations - Remove deprecated models/resources (customers, setlists, invitations, etc.) - Refresh admin app and docs; remove apps/band Made-with: Cursor
This commit is contained in:
@@ -4,129 +4,52 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\EventStatus;
|
||||
use App\Enums\EventVisibility;
|
||||
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 Event extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'description',
|
||||
'location_id',
|
||||
'customer_id',
|
||||
'setlist_id',
|
||||
'event_date',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'load_in_time',
|
||||
'soundcheck_time',
|
||||
'fee',
|
||||
'currency',
|
||||
'organisation_id',
|
||||
'name',
|
||||
'slug',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'timezone',
|
||||
'status',
|
||||
'visibility',
|
||||
'rsvp_deadline',
|
||||
'notes',
|
||||
'internal_notes',
|
||||
'is_public_setlist',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'event_date' => 'date',
|
||||
'start_time' => 'datetime:H:i',
|
||||
'end_time' => 'datetime:H:i',
|
||||
'load_in_time' => 'datetime:H:i',
|
||||
'soundcheck_time' => 'datetime:H:i',
|
||||
'fee' => 'decimal:2',
|
||||
'status' => EventStatus::class,
|
||||
'visibility' => EventVisibility::class,
|
||||
'rsvp_deadline' => 'datetime',
|
||||
'is_public_setlist' => 'boolean',
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
];
|
||||
}
|
||||
|
||||
// Relationships
|
||||
|
||||
public function location(): BelongsTo
|
||||
public function organisation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Location::class);
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
|
||||
public function customer(): BelongsTo
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function setlist(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Setlist::class);
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
return $this->belongsToMany(User::class, 'event_user_roles')
|
||||
->withPivot('role')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function invitations(): HasMany
|
||||
{
|
||||
return $this->hasMany(EventInvitation::class);
|
||||
}
|
||||
|
||||
// Scopes
|
||||
|
||||
public function scopeUpcoming(Builder $query): Builder
|
||||
{
|
||||
return $query->where('event_date', '>=', now()->toDateString())
|
||||
->orderBy('event_date');
|
||||
}
|
||||
|
||||
public function scopePast(Builder $query): Builder
|
||||
{
|
||||
return $query->where('event_date', '<', now()->toDateString())
|
||||
->orderByDesc('event_date');
|
||||
}
|
||||
|
||||
public function scopeConfirmed(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', EventStatus::Confirmed);
|
||||
}
|
||||
|
||||
public function scopeForUser(Builder $query, User $user): Builder
|
||||
{
|
||||
return $query->whereHas('invitations', fn (Builder $q) => $q->where('user_id', $user->id));
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
|
||||
public function isUpcoming(): bool
|
||||
{
|
||||
return $this->event_date->isFuture() || $this->event_date->isToday();
|
||||
}
|
||||
|
||||
public function isPast(): bool
|
||||
{
|
||||
return $this->event_date->isPast() && !$this->event_date->isToday();
|
||||
}
|
||||
|
||||
public function isConfirmed(): bool
|
||||
{
|
||||
return $this->status === EventStatus::Confirmed;
|
||||
}
|
||||
|
||||
public function isCancelled(): bool
|
||||
{
|
||||
return $this->status === EventStatus::Cancelled;
|
||||
return $this->hasMany(UserInvitation::class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user