Skip to content

Commit

Permalink
Merge pull request #1513 from bakaphp/hotfix-checklist-udpate
Browse files Browse the repository at this point in the history
refact: checklist update
  • Loading branch information
kaioken authored Jun 13, 2024
2 parents 1c0adf3 + d9fffb2 commit c77c7d1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace App\GraphQL\ActionEngine\Mutations\Engagements;

use Kanvas\ActionEngine\Tasks\Models\TaskEngagementItem;
use Kanvas\ActionEngine\Tasks\Models\TaskListItem;
use Kanvas\Apps\Models\Apps;
use Kanvas\Exceptions\ValidationException;
use Kanvas\Guild\Leads\Models\Lead;

class TaskEngagementMutation
{
Expand All @@ -17,19 +19,35 @@ public function changeEngagementTaskItemStatus(mixed $rootValue, array $request)
$company = $user->getCurrentCompany();
$app = app(Apps::class);
$status = $request['status'];
$lead = Lead::getByIdFromCompanyApp($request['lead_id'], $company, $app);

$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->companies_id != $company->getId()) {
throw new ValidationException('You are not allowed to change the status of this task , company mismatch');
}

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

$taskListItem->status = $status;
$taskEngagementItem = TaskEngagementItem::fromCompany($company)
->fromApp($app)
->where('task_list_item_id', $taskListItem->getId())
->where('lead_id', $lead->getId())
->first();

if (! $taskEngagementItem) {
$taskEngagementItem = new TaskEngagementItem();
$taskEngagementItem->task_list_item_id = $taskListItem->getId();
$taskEngagementItem->lead_id = $lead->getId();
$taskEngagementItem->companies_id = $company->getId();
$taskEngagementItem->apps_id = $app->getId();
$taskEngagementItem->users_id = $user->getId();
}

$taskEngagementItem->status = $status;

return $taskListItem->saveOrFail();
return $taskEngagementItem->saveOrFail();
}
}
2 changes: 1 addition & 1 deletion graphql/schemas/ActionEngine/task.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extend type Query @guard {
}

extend type Mutation @guard {
changeTaskEngagementItemStatus(id: ID!, status: String!): Boolean!
changeTaskEngagementItemStatus(id: ID!, lead_id: ID!, status: String!): Boolean!
@field(
resolver: "App\\GraphQL\\ActionEngine\\Mutations\\Engagements\\TaskEngagementMutation@changeEngagementTaskItemStatus"
)
Expand Down
6 changes: 3 additions & 3 deletions src/Baka/Traits/KanvasModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function getByName(string $name, ?AppInterface $app = null): self
->firstOrFail();
} catch (ModelNotFoundException $e) {
//we want to expose the not found msg
throw new ExceptionsModelNotFoundException("No record found for $name");
throw new ExceptionsModelNotFoundException($e->getMessage() . " $name");
}
}

Expand All @@ -58,7 +58,7 @@ public static function getByUuid(string $uuid, ?AppInterface $app = null): self
->firstOrFail();
} catch (ModelNotFoundException $e) {
//we want to expose the not found msg
throw new ExceptionsModelNotFoundException("No record found for $uuid");
throw new ExceptionsModelNotFoundException($e->getMessage() . " $uuid");
}
}

Expand All @@ -73,7 +73,7 @@ public static function getById(mixed $id, ?AppInterface $app = null): self
->firstOrFail();
} catch (ModelNotFoundException $e) {
//we want to expose the not found msg
throw new ExceptionsModelNotFoundException("No record found for $id");
throw new ExceptionsModelNotFoundException($e->getMessage() . " $id");
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Domains/ActionEngine/Tasks/Models/TaskEngagementItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kanvas\ActionEngine\Tasks\Models;

use Baka\Casts\Json;
use Baka\Traits\HasCompositePrimaryKeyTrait;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Kanvas\ActionEngine\Engagements\Models\Engagement;
Expand All @@ -25,13 +26,17 @@
*/
class TaskEngagementItem extends BaseModel
{
use HasCompositePrimaryKeyTrait;

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

protected $casts = [
'config' => Json::class,
];

protected $primaryKey = ['task_list_item_id','lead_id'];

public function item(): BelongsTo
{
return $this->belongsTo(TaskListItem::class, 'task_list_item_id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class VariantWarehouseStatusHistory extends BaseModel
protected $primaryKey = ['products_variants_warehouse_id', 'status_id'];
protected $forceDeleting = true;


/**
* Get the user that owns the Variants.
*/
Expand Down

0 comments on commit c77c7d1

Please sign in to comment.