From 682760e9716ddd8acd5ae54996ed61cb6f21f346 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 12 Jun 2024 11:11:29 -0400 Subject: [PATCH 1/3] refact: remove apps and companies from morph table --- .../Social/Mutations/Tags/TagsManagement.php | 4 ++-- .../2024_06_12_041705_refact_tags_entities.php | 14 ++++++++------ graphql/schemas/Guild/people.graphql | 2 +- src/Domains/Social/Tags/Traits/HasTagsTrait.php | 12 ++---------- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app/GraphQL/Social/Mutations/Tags/TagsManagement.php b/app/GraphQL/Social/Mutations/Tags/TagsManagement.php index 20e73e0f3..0fda51242 100644 --- a/app/GraphQL/Social/Mutations/Tags/TagsManagement.php +++ b/app/GraphQL/Social/Mutations/Tags/TagsManagement.php @@ -90,8 +90,8 @@ public function attachTagToEntity(mixed $root, array $request): bool $tag->entities()->attach($entity->getId(), [ //'entity_namespace' => $systemModule->model_name, - 'apps_id' => $tag->apps_id, - 'companies_id' => $user->getCurrentCompany()->getId(), + //'apps_id' => $tag->apps_id, + //'companies_id' => $user->getCurrentCompany()->getId(), 'users_id' => $user->getId(), 'taggable_type' => $systemModule->model_name, ]); diff --git a/database/migrations/Social/2024_06_12_041705_refact_tags_entities.php b/database/migrations/Social/2024_06_12_041705_refact_tags_entities.php index a963475b5..3b7308bb9 100644 --- a/database/migrations/Social/2024_06_12_041705_refact_tags_entities.php +++ b/database/migrations/Social/2024_06_12_041705_refact_tags_entities.php @@ -10,12 +10,12 @@ */ public function up(): void { - //remove field entity_namespace from tags_entities - if (Schema::hasColumn('tags_entities', 'entity_namespace')) { - Schema::table('tags_entities', function (Blueprint $table) { - $table->dropColumn('entity_namespace'); - }); - } + Schema::table('tags_entities', function (Blueprint $table) { + $table->dropColumn('entity_namespace'); + $table->dropColumn('apps_id'); + $table->dropColumn('companies_id'); + }); + } /** @@ -25,6 +25,8 @@ public function down(): void { Schema::table('tags_entities', function (Blueprint $table) { $table->string('entity_namespace', 255)->nullable(); + $table->integer('apps_id')->nullable(); + $table->integer('companies_id')->nullable(); }); } }; diff --git a/graphql/schemas/Guild/people.graphql b/graphql/schemas/Guild/people.graphql index 6877e96e9..a5e7b637b 100644 --- a/graphql/schemas/Guild/people.graphql +++ b/graphql/schemas/Guild/people.graphql @@ -88,7 +88,7 @@ extend type Query @guard { ): [People!]! @paginate( model: "Kanvas\\Guild\\Customers\\Models\\People" - scopes: ["fromApp", "fromCompany", "notDeleted"] + scopes: [ "notDeleted"] defaultCount: 25 ) peopleRelationships( diff --git a/src/Domains/Social/Tags/Traits/HasTagsTrait.php b/src/Domains/Social/Tags/Traits/HasTagsTrait.php index 860bc4d81..27dc59253 100644 --- a/src/Domains/Social/Tags/Traits/HasTagsTrait.php +++ b/src/Domains/Social/Tags/Traits/HasTagsTrait.php @@ -15,18 +15,12 @@ trait HasTagsTrait { - public function tags(bool $userCompany = true): MorphToMany + public function tags(): MorphToMany { $dbConnection = config('database.connections.social.database'); $query = $this->morphToMany(ModelsTag::class, 'taggable', $dbConnection . '.tags_entities', 'entity_id', 'tags_id') - ->using(TagEntity::class) - ->wherePivot('apps_id', $this->apps_id); - - - if ($userCompany) { - $query->wherePivot('companies_id', $this->companies_id); - } + ->using(TagEntity::class); return $query; } @@ -51,8 +45,6 @@ public function addTag( ))->execute(); $this->tags()->attach($this->getId(), [ - 'companies_id' => $company->getId(), - 'apps_id' => $app->getId(), 'tags_id' => $tag->getId(), 'users_id' => $user->getId(), 'is_deleted' => 0, From c4b705a3d7c8437552e763b56273f70276885bda Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 12 Jun 2024 11:13:25 -0400 Subject: [PATCH 2/3] refact: add relationship --- .../migrations/Social/2024_06_12_041705_refact_tags_entities.php | 1 - 1 file changed, 1 deletion(-) diff --git a/database/migrations/Social/2024_06_12_041705_refact_tags_entities.php b/database/migrations/Social/2024_06_12_041705_refact_tags_entities.php index 3b7308bb9..00313e3ee 100644 --- a/database/migrations/Social/2024_06_12_041705_refact_tags_entities.php +++ b/database/migrations/Social/2024_06_12_041705_refact_tags_entities.php @@ -15,7 +15,6 @@ public function up(): void $table->dropColumn('apps_id'); $table->dropColumn('companies_id'); }); - } /** From 9e5b1aeca436e2ac94d5f06270778b3e29797e30 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 12 Jun 2024 11:15:46 -0400 Subject: [PATCH 3/3] refact: return scope --- graphql/schemas/Guild/people.graphql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/schemas/Guild/people.graphql b/graphql/schemas/Guild/people.graphql index a5e7b637b..6877e96e9 100644 --- a/graphql/schemas/Guild/people.graphql +++ b/graphql/schemas/Guild/people.graphql @@ -88,7 +88,7 @@ extend type Query @guard { ): [People!]! @paginate( model: "Kanvas\\Guild\\Customers\\Models\\People" - scopes: [ "notDeleted"] + scopes: ["fromApp", "fromCompany", "notDeleted"] defaultCount: 25 ) peopleRelationships(