feat(event): restore event model and migrate tenant event data

This commit is contained in:
2026-09-18 11:31:51 -03:00
parent 1e67d27a90
commit 0170a2eabb
13 changed files with 339 additions and 81 deletions

View File

@@ -44,17 +44,37 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
'tenant_code' => $tenant->codigo,
]));
$tenant->update([
'event_title' => 'Fiesta Nacional del Fútbol Infantil',
'event_location' => 'Sunchales, Santa Fe',
]);
$event = $tenant->events()->firstOrCreate(
['title' => 'Fiesta Nacional del Fútbol Infantil'],
['location' => 'Sunchales, Santa Fe', 'published_at' => now()],
);
$event->update(['location' => 'Sunchales, Santa Fe']);
if ($tenant->storefront_website_type_code === 'onticket' && $tenant->active_event_id === null) {
$tenant->update(['active_event_id' => $event->id]);
}
$existingCodes = $event->socialMedia()->pluck('social_media.code')->all();
$missingSocialMedia = $tenant->socialMedia()
->get()
->reject(fn ($network): bool => in_array($network->code, $existingCodes, true))
->mapWithKeys(fn ($network): array => [
$network->code => [
'url' => $network->pivot->url,
'orden' => $network->pivot->orden,
],
])
->all();
if ($missingSocialMedia !== []) {
$event->socialMedia()->syncWithoutDetaching($missingSocialMedia);
}
$existingValidityTimeIds = $tenant->eventDates()->pluck('validity_time_id');
$tenant->eventDates()->delete();
$event->dates()->delete();
ValidityTime::query()->whereKey($existingValidityTimeIds)->delete();
$eventDates = collect(['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'])
->map(function (string $date) use ($tenant): EventDate {
->map(function (string $date) use ($tenant, $event): EventDate {
$validityTime = ValidityTime::query()->create([
'type' => ValidityTimeType::FixedWindow,
'start_time' => null,
@@ -69,9 +89,10 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
'time_start' => '00:00:00',
'time_end' => '23:59:59',
'validity_time_id' => $validityTime->id,
'tenant_code' => $tenant->codigo,
]);
return $tenant->eventDates()->save($eventDate);
return $event->dates()->save($eventDate);
});
$dateIds = $eventDates->pluck('id')->map(fn ($id): int => (int) $id)->values();