merge: client-owned integrations into dev

This commit is contained in:
ncoronel 2026-08-18 17:34:31 -03:00
commit 67e6211857
5 changed files with 68 additions and 81 deletions

View File

@ -20,7 +20,6 @@ class ClientResource extends JsonResource
'codigo' => $tenant->codigo, 'codigo' => $tenant->codigo,
'nombre' => $tenant->nombre, 'nombre' => $tenant->nombre,
'dominio' => $tenant->dominio, 'dominio' => $tenant->dominio,
'base_path' => $tenant->base_path,
])), ])),
]; ];
} }

View File

@ -9,35 +9,27 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (! Schema::hasTable('clients')) {
Schema::create('clients', function (Blueprint $table): void { Schema::create('clients', function (Blueprint $table): void {
$table->id(); $table->id();
$table->string('code')->unique(); $table->string('code')->unique();
$table->string('name'); $table->string('name');
$table->timestamps(); $table->timestamps();
}); });
}
if (! Schema::hasColumn('tenants', 'client_id')) {
Schema::table('tenants', function (Blueprint $table): void { Schema::table('tenants', function (Blueprint $table): void {
$table->foreignId('client_id')->nullable()->after('id')->constrained('clients')->restrictOnDelete(); $table->foreignId('client_id')->nullable()->after('id')->constrained('clients')->restrictOnDelete();
}); });
}
DB::table('tenants') DB::table('tenants')
->select(['id', 'codigo', 'nombre', 'created_at', 'updated_at']) ->select(['id', 'codigo', 'nombre', 'created_at', 'updated_at'])
->orderBy('id') ->orderBy('id')
->each(function (object $tenant): void { ->each(function (object $tenant): void {
$clientId = DB::table('clients')->where('code', $tenant->codigo)->value('id');
if ($clientId === null) {
$clientId = DB::table('clients')->insertGetId([ $clientId = DB::table('clients')->insertGetId([
'code' => $tenant->codigo, 'code' => $tenant->codigo,
'name' => $tenant->nombre, 'name' => $tenant->nombre,
'created_at' => $tenant->created_at ?? now(), 'created_at' => $tenant->created_at ?? now(),
'updated_at' => $tenant->updated_at ?? now(), 'updated_at' => $tenant->updated_at ?? now(),
]); ]);
}
DB::table('tenants')->where('id', $tenant->id)->update(['client_id' => $clientId]); DB::table('tenants')->where('id', $tenant->id)->update(['client_id' => $clientId]);
}); });

View File

@ -9,7 +9,6 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (! Schema::hasTable('client_integrations')) {
Schema::create('client_integrations', function (Blueprint $table): void { Schema::create('client_integrations', function (Blueprint $table): void {
$table->id(); $table->id();
$table->foreignId('client_id')->constrained('clients')->cascadeOnDelete(); $table->foreignId('client_id')->constrained('clients')->cascadeOnDelete();
@ -23,9 +22,7 @@ return new class extends Migration
->cascadeOnDelete(); ->cascadeOnDelete();
$table->unique(['client_id', 'integration_code']); $table->unique(['client_id', 'integration_code']);
}); });
}
if (Schema::hasTable('tenant_integration')) {
DB::table('tenant_integration') DB::table('tenant_integration')
->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code') ->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code')
->select([ ->select([
@ -49,15 +46,11 @@ return new class extends Migration
], ],
); );
}); });
}
if (! Schema::hasColumn('integrations', 'requires_client_configuration')) {
Schema::table('integrations', function (Blueprint $table): void { Schema::table('integrations', function (Blueprint $table): void {
$table->boolean('requires_client_configuration')->default(true); $table->boolean('requires_client_configuration')->default(true);
}); });
}
if (Schema::hasColumn('integrations', 'requires_tenant_configuration')) {
DB::table('integrations')->update([ DB::table('integrations')->update([
'requires_client_configuration' => DB::raw('requires_tenant_configuration'), 'requires_client_configuration' => DB::raw('requires_tenant_configuration'),
]); ]);
@ -65,7 +58,6 @@ return new class extends Migration
Schema::table('integrations', function (Blueprint $table): void { Schema::table('integrations', function (Blueprint $table): void {
$table->dropColumn('requires_tenant_configuration'); $table->dropColumn('requires_tenant_configuration');
}); });
}
Schema::dropIfExists('tenant_integration'); Schema::dropIfExists('tenant_integration');
} }

View File

@ -40,11 +40,7 @@ class DesfilePuraTendenciaSeeder extends Seeder
$tenant = Tenant::query()->where('codigo', self::TENANT_CODE)->first(); $tenant = Tenant::query()->where('codigo', self::TENANT_CODE)->first();
if ($tenant) { if ($tenant) {
$tenant->update([ $tenant->update(['client_id' => $client->id]);
'client_id' => $client->id,
'cart_editing_enabled' => false,
'display_cart_item_images' => false,
]);
return; return;
} }

View File

@ -16,6 +16,8 @@ class TenantSeeder extends Seeder
{ {
private const ONTICKET_CLIENT_CODE = 'onticket'; private const ONTICKET_CLIENT_CODE = 'onticket';
private const SONDER_CLIENT_CODE = 'sonder';
private const SOCIAL_MEDIA = [ private const SOCIAL_MEDIA = [
[ [
'code' => 'instagram', 'code' => 'instagram',
@ -43,6 +45,11 @@ class TenantSeeder extends Seeder
public function run(): void public function run(): void
{ {
$sonderClient = Client::query()->firstOrCreate(
['code' => self::SONDER_CLIENT_CODE],
['name' => 'Sonder'],
);
$onTicketClient = Client::query()->firstOrCreate( $onTicketClient = Client::query()->firstOrCreate(
['code' => self::ONTICKET_CLIENT_CODE], ['code' => self::ONTICKET_CLIENT_CODE],
['name' => 'OnTicket'], ['name' => 'OnTicket'],
@ -55,6 +62,7 @@ class TenantSeeder extends Seeder
->delete(); ->delete();
$this->tenantService->create([ $this->tenantService->create([
'client_id' => $sonderClient->id,
'codigo' => 'sonder', 'codigo' => 'sonder',
'nombre' => 'Sonder', 'nombre' => 'Sonder',
'dominio' => 'localhost', 'dominio' => 'localhost',