feat: harden tenant settings and import pipeline
This commit is contained in:
32
database/factories/EmotionFactory.php
Normal file
32
database/factories/EmotionFactory.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Emotion;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class EmotionFactory extends Factory
|
||||
{
|
||||
protected $model = Emotion::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$name = ucfirst($this->faker->unique()->word());
|
||||
|
||||
return [
|
||||
'name' => [
|
||||
'en' => $name,
|
||||
'de' => $name,
|
||||
],
|
||||
'icon' => $this->faker->randomElement(['smile', 'heart', 'star', 'sparkles']),
|
||||
'color' => $this->faker->hexColor(),
|
||||
'description' => [
|
||||
'en' => $this->faker->sentence(),
|
||||
'de' => $this->faker->sentence(),
|
||||
],
|
||||
'sort_order' => $this->faker->numberBetween(0, 20),
|
||||
'is_active' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventType;
|
||||
use App\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -18,12 +19,14 @@ class EventFactory extends Factory
|
||||
|
||||
return [
|
||||
'tenant_id' => Tenant::factory(),
|
||||
'event_type_id' => EventType::factory(),
|
||||
'name' => $name,
|
||||
'slug' => $slug,
|
||||
'description' => $this->faker->paragraph(),
|
||||
'date' => $this->faker->dateTimeBetween('now', '+6 months'),
|
||||
'location' => $this->faker->address(),
|
||||
'max_participants' => $this->faker->numberBetween(50, 500),
|
||||
'settings' => null,
|
||||
'is_active' => true,
|
||||
'join_link_enabled' => true,
|
||||
'photo_upload_enabled' => true,
|
||||
@@ -60,4 +63,5 @@ class EventFactory extends Factory
|
||||
'date' => $this->faker->dateTimeBetween('now', '+1 month'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
31
database/factories/EventTypeFactory.php
Normal file
31
database/factories/EventTypeFactory.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\EventType;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EventTypeFactory extends Factory
|
||||
{
|
||||
protected $model = EventType::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$name = ucfirst($this->faker->unique()->words(2, true));
|
||||
$slug = Str::slug($name);
|
||||
|
||||
return [
|
||||
'name' => [
|
||||
'de' => $name,
|
||||
'en' => $name,
|
||||
],
|
||||
'slug' => $slug,
|
||||
'icon' => $this->faker->randomElement(['party', 'camera', 'users', null]),
|
||||
'settings' => [
|
||||
'color' => $this->faker->hexColor(),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
48
database/factories/PhotoFactory.php
Normal file
48
database/factories/PhotoFactory.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Emotion;
|
||||
use App\Models\Event;
|
||||
use App\Models\Photo;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PhotoFactory extends Factory
|
||||
{
|
||||
protected $model = Photo::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'event_id' => Event::factory(),
|
||||
'emotion_id' => Emotion::factory(),
|
||||
'task_id' => null,
|
||||
'guest_name' => $this->faker->name(),
|
||||
'file_path' => 'photos/' . Str::uuid() . '.jpg',
|
||||
'thumbnail_path' => 'photos/thumbnails/' . Str::uuid() . '.jpg',
|
||||
'likes_count' => $this->faker->numberBetween(0, 25),
|
||||
'is_featured' => false,
|
||||
'metadata' => ['factory' => true],
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterMaking(function (Photo $photo) {
|
||||
if (! $photo->tenant_id && $photo->event) {
|
||||
$photo->tenant_id = $photo->event->tenant_id;
|
||||
}
|
||||
})->afterCreating(function (Photo $photo) {
|
||||
if ($photo->event && ! $photo->tenant_id) {
|
||||
$photo->tenant_id = $photo->event->tenant_id;
|
||||
$photo->save();
|
||||
}
|
||||
|
||||
if ($photo->tenant_id && $photo->event && $photo->event->tenant_id !== $photo->tenant_id) {
|
||||
$photo->event->update(['tenant_id' => $photo->tenant_id]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
29
database/factories/PurchaseHistoryFactory.php
Normal file
29
database/factories/PurchaseHistoryFactory.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\PurchaseHistory;
|
||||
use App\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PurchaseHistoryFactory extends Factory
|
||||
{
|
||||
protected $model = PurchaseHistory::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'id' => (string) Str::uuid(),
|
||||
'tenant_id' => Tenant::factory(),
|
||||
'package_id' => $this->faker->randomElement(['starter', 'pro', 'enterprise']),
|
||||
'credits_added' => $this->faker->numberBetween(1, 10),
|
||||
'price' => $this->faker->randomFloat(2, 9, 199),
|
||||
'currency' => 'EUR',
|
||||
'platform' => $this->faker->randomElement(['tenant-app', 'ios', 'android']),
|
||||
'transaction_id' => (string) Str::uuid(),
|
||||
'purchased_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,17 +14,19 @@ class TenantFactory extends Factory
|
||||
{
|
||||
$name = $this->faker->company();
|
||||
$slug = Str::slug($name);
|
||||
$contactEmail = $this->faker->companyEmail();
|
||||
|
||||
return [
|
||||
'name' => $name,
|
||||
'slug' => $slug,
|
||||
'contact_email' => $this->faker->companyEmail(),
|
||||
'contact_email' => $contactEmail,
|
||||
'event_credits_balance' => $this->faker->numberBetween(1, 20),
|
||||
'subscription_tier' => $this->faker->randomElement(['free', 'starter', 'pro']),
|
||||
'subscription_expires_at' => $this->faker->dateTimeBetween('now', '+1 year'),
|
||||
'is_active' => true,
|
||||
'is_suspended' => false,
|
||||
'settings' => json_encode([
|
||||
'settings_updated_at' => now(),
|
||||
'settings' => [
|
||||
'branding' => [
|
||||
'logo_url' => null,
|
||||
'primary_color' => '#3B82F6',
|
||||
@@ -38,8 +40,9 @@ class TenantFactory extends Factory
|
||||
'advanced_analytics' => false,
|
||||
],
|
||||
'custom_domain' => null,
|
||||
]),
|
||||
'settings_updated_at' => now(),
|
||||
'contact_email' => $contactEmail,
|
||||
'event_default_type' => 'general',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -63,4 +66,5 @@ class TenantFactory extends Factory
|
||||
'event_credits_balance' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user