Skip to content

Commit

Permalink
Merge pull request #1489 from bakaphp/refact-tags
Browse files Browse the repository at this point in the history
refact: add relationship
  • Loading branch information
kaioken authored Jun 12, 2024
2 parents b38c1ca + 61fda61 commit de46caa
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\ActionEngine\Mutations\Engagements;

use Kanvas\ActionEngine\Tasks\Models\TaskListItem;
use Kanvas\Apps\Models\Apps;
use Kanvas\Exceptions\ValidationException;

class TaskEngagementMutation
{
public function changeEngagementTaskItemStatus(mixed $rootValue, array $request): bool
{
$id = (int) $request['id'];
$user = auth()->user();
$company = $user->getCurrentCompany();
$app = app(Apps::class);
$status = $request['status'];

$taskListItem = TaskListItem::getById($id);

if ($taskListItem->companyAction->company_id != $company->getId()) {
throw new ValidationException('You are not allowed to change the status of this task');
}

if ($taskListItem->companyAction->apps_id != $app->getId()) {
throw new ValidationException('You are not allowed to change the status of this task');
}

$taskListItem->status = $status;

return $taskListItem->saveOrFail();
}
}
7 changes: 7 additions & 0 deletions graphql/schemas/ActionEngine/task.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ extend type Query @guard {
defaultCount: 25
)
}

extend type Mutation @guard {
changeTaskEngagementItemStatus(id: ID!, status: String!): Boolean!
@field(
resolver: "App\\GraphQL\\ActionEngine\\Mutations\\Engagements\\TaskEngagementMutation@changeEngagementTaskItemStatus"
)
}
2 changes: 2 additions & 0 deletions graphql/schemas/Guild/people.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ extend type Query @guard {
@whereHasConditions(relation: "emails", columns: ["id", "value"])
hasPhones: _
@whereHasConditions(relation: "phones", columns: ["id", "value"])
hasTags: _
@whereHasConditions(relation: "tags", columns: ["name"])
hasCustomFields: _
@whereHasConditions(
relation: "customFields"
Expand Down
6 changes: 3 additions & 3 deletions src/Domains/Social/Messages/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Kanvas\Social\Messages\Models;

use Baka\Casts\Json;
use Baka\Traits\SoftDeletesTrait;
use Baka\Traits\UuidTrait;
use Dyrynda\Database\Support\CascadeSoftDeletes;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -18,12 +20,10 @@
use Kanvas\Social\MessagesComments\Models\MessageComment;
use Kanvas\Social\MessagesTypes\Models\MessageType;
use Kanvas\Social\Models\BaseModel;
use Kanvas\Social\Tags\Traits\HasTagsTrait;
use Kanvas\Social\Topics\Models\Topic;
use Kanvas\Users\Models\Users;
use Laravel\Scout\Searchable;
use Baka\Traits\SoftDeletesTrait;
use Dyrynda\Database\Support\CascadeSoftDeletes;
use Kanvas\Social\Tags\Traits\HasTagsTrait;

/**
* Class Message
Expand Down
8 changes: 8 additions & 0 deletions src/Domains/Social/Tags/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kanvas\Social\Tags\Models;

use Baka\Traits\SlugTrait;
use Illuminate\Support\Facades\DB;
use Kanvas\Social\Models\BaseModel;

/**
Expand All @@ -22,6 +23,7 @@ class Tag extends BaseModel
use SlugTrait;

protected $guarded = [];
protected $table = 'tags';

public function taggables()
{
Expand All @@ -34,4 +36,10 @@ public function entities()
->using(TagEntity::class)
->withPivot('entity_namespace', 'companies_id', 'apps_id', 'users_id', 'is_deleted', 'created_at', 'updated_at');
}

public function getTable()
{
$databaseName = DB::connection($this->connection)->getDatabaseName();
return $databaseName . '.tags';
}
}

0 comments on commit de46caa

Please sign in to comment.