feat(event): replace variants when dates change

This commit is contained in:
2026-09-14 14:09:42 -03:00
parent aa14129fe7
commit e42bc545a5
5 changed files with 188 additions and 14 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Domains\Event\Services;
use App\Domains\Catalog\Models\Variant;
use App\Domains\Catalog\Services\VariantReplacementService;
use App\Domains\Event\Events\EventDateRescheduled;
use App\Domains\Event\Events\EventDateSuspended;
use App\Domains\Event\Models\EventDate;
@@ -23,6 +24,7 @@ class EventService
public function __construct(
private readonly EffectiveEventDateResolver $effectiveEventDateResolver,
private readonly AffectedEventDatePurchaseResolver $affectedPurchaseResolver,
private readonly VariantReplacementService $variantReplacementService,
) {}
public function forTenant(Tenant $tenant): Tenant
@@ -109,7 +111,8 @@ class EventService
]);
}
if ($this->effectiveEventDateResolver->resolve($destination) === null) {
$effectiveDestination = $this->effectiveEventDateResolver->resolve($destination);
if ($effectiveDestination === null) {
throw ValidationException::withMessages([
'date' => ['La fecha de destino no es utilizable.'],
]);
@@ -120,6 +123,7 @@ class EventService
$this->affectedDateIds($tenant, $source),
);
$source->update(['rescheduled_to_event_date_id' => $destination->getKey()]);
$this->variantReplacementService->replaceEventDate($source, $effectiveDestination);
EventDateRescheduled::dispatch(
$tenant->codigo,
@@ -154,6 +158,7 @@ class EventService
$this->affectedDateIds($tenant, $date),
);
$date->update(['suspended_at' => now()]);
$this->variantReplacementService->disableForSuspension($date);
$this->disableTicketsWithoutUsableDates($tenant, $date);
EventDateSuspended::dispatch(