feat: Add event management to tenant and catalog
- Introduced Event and EventDate models with relationships to Tenant and CatalogItem. - Added active_event_id to Tenant model to track the currently active event. - Updated TenantResource to include active event details in the response. - Enhanced Ticket model to link to CatalogItem and Variant, allowing for event-specific ticketing. - Implemented migrations to create events and link them to catalog items and variants. - Updated seeders to populate events and their associated dates for the Fiesta Futbol Infantil tenant. - Modified Ticket generation logic to respect event dates over standard ticket dates. - Added tests for event and ticket functionalities, ensuring proper relationships and date handling.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('events', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('tenant_code');
|
||||
$table->string('name');
|
||||
$table->string('address');
|
||||
|
||||
$table->foreign('tenant_code')
|
||||
->references('codigo')
|
||||
->on('tenants')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
|
||||
Schema::create('event_dates', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('event_id')->constrained('events')->cascadeOnDelete();
|
||||
$table->date('date');
|
||||
$table->time('time_start');
|
||||
$table->time('time_end');
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreignId('active_event_id')
|
||||
->nullable()
|
||||
->constrained('events')
|
||||
->nullOnDelete();
|
||||
});
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')
|
||||
->nullable()
|
||||
->after('tenant_code')
|
||||
->constrained('events')
|
||||
->nullOnDelete();
|
||||
$table->enum('event_product_type', EventProductType::values())
|
||||
->nullable()
|
||||
->after('event_id');
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->foreignId('event_date_id')
|
||||
->nullable()
|
||||
->after('catalog_item_id')
|
||||
->constrained('event_dates')
|
||||
->nullOnDelete();
|
||||
$table->unique(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('active_event_id');
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->dropUnique(['catalog_item_id', 'event_date_id']);
|
||||
$table->dropConstrainedForeignId('event_date_id');
|
||||
});
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
$table->dropColumn('event_product_type');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('event_dates');
|
||||
Schema::dropIfExists('events');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('tickets')
|
||||
->whereNotNull('source_variant_id')
|
||||
->whereNotIn('source_variant_id', DB::table('variantes')->select('id'))
|
||||
->update(['source_variant_id' => null]);
|
||||
|
||||
DB::table('tickets')
|
||||
->whereNotNull('source_catalog_item_id')
|
||||
->whereNotIn('source_catalog_item_id', DB::table('catalog_items')->select('id'))
|
||||
->update(['source_catalog_item_id' => null]);
|
||||
|
||||
Schema::table('tickets', function (Blueprint $table): void {
|
||||
$table->foreign('source_catalog_item_id')
|
||||
->references('id')
|
||||
->on('catalog_items')
|
||||
->cascadeOnUpdate()
|
||||
->nullOnDelete();
|
||||
$table->foreign('source_variant_id')
|
||||
->references('id')
|
||||
->on('variantes')
|
||||
->cascadeOnUpdate()
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tickets', function (Blueprint $table): void {
|
||||
$table->dropForeign(['source_catalog_item_id']);
|
||||
$table->dropForeign(['source_variant_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user