feat(event): suspend event dates instead of cancelling

This commit is contained in:
2026-09-11 15:57:17 -03:00
parent 96df431d60
commit 1880fc8147
10 changed files with 52 additions and 29 deletions

View File

@@ -56,10 +56,10 @@ class EventController extends Controller
);
}
public function cancelDate(Request $request, EventDate $eventDate): EventDateResource
public function suspendDate(Request $request, EventDate $eventDate): EventDateResource
{
return EventDateResource::make(
$this->eventService->cancelDateForTenant(
$this->eventService->suspendDateForTenant(
$request->user()->tenant()->firstOrFail(),
$eventDate,
)

View File

@@ -5,7 +5,7 @@ namespace App\Domains\Event\Enums;
enum EventDateStatus: string
{
case Rescheduled = 'rescheduled';
case Cancelled = 'cancelled';
case Suspended = 'suspended';
case Scheduled = 'scheduled';
case InProgress = 'in_progress';
case Completed = 'completed';

View File

@@ -23,7 +23,7 @@ use Illuminate\Support\Carbon;
'time_start',
'time_end',
'rescheduled_to_event_date_id',
'cancelled_at',
'suspended_at',
])]
class EventDate extends Model
{
@@ -58,7 +58,7 @@ class EventDate extends Model
'date' => 'date:Y-m-d',
'validity_time_id' => 'integer',
'rescheduled_to_event_date_id' => 'integer',
'cancelled_at' => 'datetime',
'suspended_at' => 'datetime',
];
}
@@ -119,8 +119,8 @@ class EventDate extends Model
return EventDateStatus::Rescheduled;
}
if ($this->cancelled_at !== null) {
return EventDateStatus::Cancelled;
if ($this->suspended_at !== null) {
return EventDateStatus::Suspended;
}
if (now()->lt($this->startsAt())) {
@@ -146,7 +146,7 @@ class EventDate extends Model
'event_date_text' => app(EventDateTextFormatter::class)->format(
$tenant->eventDates()
->whereNull('rescheduled_to_event_date_id')
->whereNull('cancelled_at')
->whereNull('suspended_at')
->pluck('date')
),
]);

View File

@@ -22,7 +22,7 @@ class EventDateResource extends JsonResource
'end_time' => substr($this->time_end, 0, 5),
'status' => $this->status->value,
'rescheduled_to_event_date_id' => $this->rescheduled_to_event_date_id,
'cancelled_at' => $this->cancelled_at?->toISOString(),
'suspended_at' => $this->suspended_at?->toISOString(),
];
}
}

View File

@@ -23,7 +23,7 @@ class EffectiveEventDateResolver
$visited[$identity] = true;
if ($current->rescheduled_to_event_date_id === null) {
return $current->cancelled_at === null ? $current : null;
return $current->suspended_at === null ? $current : null;
}
$current->loadMissing('rescheduledTo');

View File

@@ -68,9 +68,9 @@ class EventService
return DB::transaction(function () use ($tenant, $eventDate, $data): EventDate {
$source = $this->lockedDateForTenant($tenant, $eventDate);
if ($source->cancelled_at !== null) {
if ($source->suspended_at !== null) {
throw ValidationException::withMessages([
'event_date' => ['No se puede reprogramar una fecha cancelada.'],
'event_date' => ['No se puede reprogramar una fecha suspendida.'],
]);
}
@@ -111,22 +111,22 @@ class EventService
});
}
public function cancelDateForTenant(Tenant $tenant, EventDate $eventDate): EventDate
public function suspendDateForTenant(Tenant $tenant, EventDate $eventDate): EventDate
{
return DB::transaction(function () use ($tenant, $eventDate): EventDate {
$date = $this->lockedDateForTenant($tenant, $eventDate);
if ($date->rescheduled_to_event_date_id !== null) {
throw ValidationException::withMessages([
'event_date' => ['No se puede cancelar una fecha que ya fue reprogramada.'],
'event_date' => ['No se puede suspender una fecha que ya fue reprogramada.'],
]);
}
if ($date->cancelled_at !== null) {
if ($date->suspended_at !== null) {
return $date->load('validityTime');
}
$date->update(['cancelled_at' => now()]);
$date->update(['suspended_at' => now()]);
$this->disableTicketsWithoutUsableDates($tenant, $date);
return $date->fresh('validityTime');
@@ -166,9 +166,9 @@ class EventService
return $current->is($expected);
}
private function disableTicketsWithoutUsableDates(Tenant $tenant, EventDate $cancelledDate): void
private function disableTicketsWithoutUsableDates(Tenant $tenant, EventDate $suspendedDate): void
{
$affectedDateIds = collect([$cancelledDate->getKey()]);
$affectedDateIds = collect([$suspendedDate->getKey()]);
$frontier = $affectedDateIds;
while ($frontier->isNotEmpty()) {

View File

@@ -10,5 +10,5 @@ Route::prefix('v1/adminapp/tenant')
Route::put('event', [EventController::class, 'update']);
Route::post('event-dates', [EventController::class, 'storeDate']);
Route::post('event-dates/{eventDate}/reschedule', [EventController::class, 'rescheduleDate']);
Route::post('event-dates/{eventDate}/cancel', [EventController::class, 'cancelDate']);
Route::post('event-dates/{eventDate}/suspend', [EventController::class, 'suspendDate']);
});