merge: client-owned integrations into dev
This commit is contained in:
commit
67e6211857
|
|
@ -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,
|
|
||||||
])),
|
])),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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');
|
$clientId = DB::table('clients')->insertGetId([
|
||||||
|
'code' => $tenant->codigo,
|
||||||
if ($clientId === null) {
|
'name' => $tenant->nombre,
|
||||||
$clientId = DB::table('clients')->insertGetId([
|
'created_at' => $tenant->created_at ?? now(),
|
||||||
'code' => $tenant->codigo,
|
'updated_at' => $tenant->updated_at ?? now(),
|
||||||
'name' => $tenant->nombre,
|
]);
|
||||||
'created_at' => $tenant->created_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]);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,63 +9,55 @@ 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();
|
$table->string('integration_code');
|
||||||
$table->string('integration_code');
|
$table->longText('integration_data')->nullable();
|
||||||
$table->longText('integration_data')->nullable();
|
$table->timestamps();
|
||||||
$table->timestamps();
|
|
||||||
|
|
||||||
$table->foreign('integration_code')
|
$table->foreign('integration_code')
|
||||||
->references('integration_code')
|
->references('integration_code')
|
||||||
->on('integrations')
|
->on('integrations')
|
||||||
->cascadeOnDelete();
|
->cascadeOnDelete();
|
||||||
$table->unique(['client_id', 'integration_code']);
|
$table->unique(['client_id', 'integration_code']);
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::table('tenant_integration')
|
||||||
|
->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code')
|
||||||
|
->select([
|
||||||
|
'tenants.client_id',
|
||||||
|
'tenant_integration.integration_code',
|
||||||
|
'tenant_integration.integration_data',
|
||||||
|
'tenant_integration.created_at',
|
||||||
|
'tenant_integration.updated_at',
|
||||||
|
])
|
||||||
|
->orderBy('tenant_integration.id')
|
||||||
|
->each(function (object $configuration): void {
|
||||||
|
DB::table('client_integrations')->updateOrInsert(
|
||||||
|
[
|
||||||
|
'client_id' => $configuration->client_id,
|
||||||
|
'integration_code' => $configuration->integration_code,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'integration_data' => $configuration->integration_data,
|
||||||
|
'created_at' => $configuration->created_at,
|
||||||
|
'updated_at' => $configuration->updated_at,
|
||||||
|
],
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (Schema::hasTable('tenant_integration')) {
|
Schema::table('integrations', function (Blueprint $table): void {
|
||||||
DB::table('tenant_integration')
|
$table->boolean('requires_client_configuration')->default(true);
|
||||||
->join('tenants', 'tenants.codigo', '=', 'tenant_integration.tenant_code')
|
});
|
||||||
->select([
|
|
||||||
'tenants.client_id',
|
|
||||||
'tenant_integration.integration_code',
|
|
||||||
'tenant_integration.integration_data',
|
|
||||||
'tenant_integration.created_at',
|
|
||||||
'tenant_integration.updated_at',
|
|
||||||
])
|
|
||||||
->orderBy('tenant_integration.id')
|
|
||||||
->each(function (object $configuration): void {
|
|
||||||
DB::table('client_integrations')->updateOrInsert(
|
|
||||||
[
|
|
||||||
'client_id' => $configuration->client_id,
|
|
||||||
'integration_code' => $configuration->integration_code,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'integration_data' => $configuration->integration_data,
|
|
||||||
'created_at' => $configuration->created_at,
|
|
||||||
'updated_at' => $configuration->updated_at,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! Schema::hasColumn('integrations', 'requires_client_configuration')) {
|
DB::table('integrations')->update([
|
||||||
Schema::table('integrations', function (Blueprint $table): void {
|
'requires_client_configuration' => DB::raw('requires_tenant_configuration'),
|
||||||
$table->boolean('requires_client_configuration')->default(true);
|
]);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Schema::hasColumn('integrations', 'requires_tenant_configuration')) {
|
Schema::table('integrations', function (Blueprint $table): void {
|
||||||
DB::table('integrations')->update([
|
$table->dropColumn('requires_tenant_configuration');
|
||||||
'requires_client_configuration' => DB::raw('requires_tenant_configuration'),
|
});
|
||||||
]);
|
|
||||||
|
|
||||||
Schema::table('integrations', function (Blueprint $table): void {
|
|
||||||
$table->dropColumn('requires_tenant_configuration');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Schema::dropIfExists('tenant_integration');
|
Schema::dropIfExists('tenant_integration');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue