-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1473 from bakaphp/feat-task-list
feat: add lead engagement task
- Loading branch information
Showing
8 changed files
with
274 additions
and
3 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
app/GraphQL/ActionEngine/Builders/Engagements/TaskEngagementBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GraphQL\ActionEngine\Builders\Engagements; | ||
|
||
use GraphQL\Type\Definition\ResolveInfo; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Kanvas\ActionEngine\Tasks\Models\TaskListItem; | ||
use Kanvas\Apps\Models\Apps; | ||
use Kanvas\Guild\Leads\Models\Lead; | ||
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext; | ||
|
||
class TaskEngagementBuilder | ||
{ | ||
public function getLeadTaskItems( | ||
mixed $root, | ||
array $args, | ||
GraphQLContext $context, | ||
ResolveInfo $resolveInfo | ||
): Builder { | ||
$company = auth()->user()->getCurrentCompany(); | ||
$user = auth()->user(); | ||
$app = app(Apps::class); | ||
|
||
$lead = Lead::getByIdFromCompanyApp($args['lead_id'], $company, $app); | ||
$leadId = $lead->getId(); | ||
|
||
return TaskListItem::leftJoin('company_task_engagement_items', function ($join) use ($lead) { | ||
$join->on('company_task_list_items.id', '=', 'company_task_engagement_items.task_list_item_id') | ||
->where('company_task_engagement_items.lead_id', '=', $lead->getId()); | ||
}) | ||
->select( | ||
'company_task_list_items.*', | ||
'company_task_engagement_items.lead_id', | ||
'company_task_engagement_items.status', | ||
'company_task_engagement_items.engagement_start_id', | ||
'company_task_engagement_items.engagement_end_id', | ||
'company_task_engagement_items.created_at', | ||
'company_task_engagement_items.updated_at' | ||
); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
database/migrations/ActionEngine/2024_06_08_173343_company_task_engagement_items.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('company_task_engagement_items', function (Blueprint $table) { | ||
$table->bigInteger('task_list_item_id')->index(); | ||
$table->bigInteger('lead_id')->index(); | ||
$table->bigInteger('companies_id')->index(); | ||
$table->bigInteger('apps_id')->index(); | ||
$table->bigInteger('users_id')->index(); | ||
$table->enum('status', ['pending', 'in_progress', 'completed'])->default('pending')->comment('pending, in_progress, completed')->index(); | ||
$table->bigInteger('engagement_start_id')->index(); | ||
$table->bigInteger('engagement_end_id')->index(); | ||
$table->json('config'); | ||
$table->timestamps(); | ||
$table->tinyInteger('is_deleted')->default(0)->index(); | ||
|
||
$table->primary(['task_list_item_id', 'lead_id']); | ||
$table->index(['task_list_item_id', 'lead_id', 'companies_id'], 'task_list_company_index'); | ||
$table->index(['task_list_item_id', 'lead_id', 'apps_id'], 'task_list_apps_index'); | ||
$table->index(['task_list_item_id', 'lead_id', 'users_id'], 'task_list_users_index'); | ||
$table->index(['task_list_item_id', 'lead_id', 'engagement_start_id'], 'task_list_engagement_start_index'); | ||
$table->index(['task_list_item_id', 'lead_id', 'engagement_end_id'], 'task_list_engagement_end_index'); | ||
$table->index(['task_list_item_id', 'lead_id', 'apps_id', 'companies_id'], 'task_list_apps_company_index'); | ||
$table->index(['task_list_item_id', 'lead_id', 'status'], 'task_list_status_index'); | ||
$table->index(['task_list_item_id', 'lead_id', 'is_deleted'], 'task_list_deleted_index'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('company_task_engagement_items'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type Engagement { | ||
id: ID! | ||
uuid: String! | ||
user: User! @belongsTo | ||
company_action: CompanyAction! @belongsTo | ||
message: Message! @belongsTo | ||
lead: Lead! @belongsTo | ||
people: People @belongsTo | ||
entity_uuid: String! | ||
slug: String! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
60 changes: 60 additions & 0 deletions
60
src/Domains/ActionEngine/Tasks/Models/TaskEngagementItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanvas\ActionEngine\Tasks\Models; | ||
|
||
use Baka\Casts\Json; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\HasOne; | ||
use Kanvas\ActionEngine\Engagements\Models\Engagement; | ||
use Kanvas\ActionEngine\Models\BaseModel; | ||
use Kanvas\Guild\Leads\Models\Lead; | ||
|
||
/** | ||
* Class TaskEngagementItem. | ||
* | ||
* @property int $task_list_item_id | ||
* @property int $lead_id | ||
* @property int $companies_id | ||
* @property int $apps_id | ||
* @property string $status | ||
* @property int $engagement_start_id | ||
* @property int $engagement_end_id | ||
* @property string $config | ||
*/ | ||
class TaskEngagementItem extends BaseModel | ||
{ | ||
protected $table = 'company_task_engagement_items'; | ||
protected $guarded = []; | ||
|
||
protected $casts = [ | ||
'config' => Json::class, | ||
]; | ||
|
||
public function item(): BelongsTo | ||
{ | ||
return $this->belongsTo(TaskListItem::class, 'task_list_item_id'); | ||
} | ||
|
||
public function lead(): BelongsTo | ||
{ | ||
return $this->belongsTo(Lead::class, 'lead_id'); | ||
} | ||
|
||
/** | ||
* temp relationship to engagement will only work on LeadTaskEngagementItem | ||
*/ | ||
public function engagementStart(): HasOne | ||
{ | ||
return $this->hasOne(Engagement::class, 'id', 'engagement_start_id'); | ||
} | ||
|
||
/** | ||
* temp relationship to engagement will only work on LeadTaskEngagementItem | ||
*/ | ||
public function engagementEnd(): HasOne | ||
{ | ||
return $this->hasOne(Engagement::class, 'id', 'engagement_end_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\GraphQL\ActionEngine; | ||
|
||
use Tests\TestCase; | ||
|
||
class CompanyTaskTest extends TestCase | ||
{ | ||
protected function createLeadAndGetResponse(array $input = []) | ||
{ | ||
$user = auth()->user(); | ||
$branch = $user->getCurrentBranch(); | ||
$title = fake()->title(); | ||
|
||
if (empty($input)) { | ||
$input = [ | ||
'branch_id' => $branch->getId(), | ||
'title' => $title, | ||
'pipeline_stage_id' => 0, | ||
'people' => [ | ||
'firstname' => fake()->firstName(), | ||
'lastname' => fake()->lastName(), | ||
'contacts' => [ | ||
[ | ||
'value' => fake()->email(), | ||
'contacts_types_id' => 1, | ||
'weight' => 0, | ||
], | ||
], | ||
'address' => [ | ||
[ | ||
'address' => fake()->address(), | ||
'city' => fake()->city(), | ||
'state' => fake()->state(), | ||
'country' => fake()->country(), | ||
'zip' => fake()->postcode(), | ||
], | ||
], | ||
], | ||
'custom_fields' => [], | ||
'files' => [ | ||
[ | ||
'url' => 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf', | ||
'name' => 'dummy.pdf', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
return $this->graphQL(' | ||
mutation($input: LeadInput!) { | ||
createLead(input: $input) { | ||
id | ||
uuid | ||
people { | ||
id | ||
}, | ||
systemModule{ | ||
id | ||
} | ||
} | ||
} | ||
', [ | ||
'input' => $input, | ||
])->json(); | ||
} | ||
|
||
public function testGetLeadTaskEngagement() | ||
{ | ||
$lead = $this->createLeadAndGetResponse(); | ||
$leadId = $lead['data']['createLead']['id']; | ||
|
||
$this->graphQL(' | ||
query leadTasks($lead_id: ID!) { | ||
leadTaskItems(lead_id: $lead_id) { | ||
data { | ||
name | ||
action { | ||
name | ||
} | ||
status | ||
config | ||
engagement_start { | ||
uuid | ||
} | ||
} | ||
} | ||
} | ||
', [ | ||
'lead_id' => $leadId, // Passing the lead ID to the GraphQL query | ||
])->assertOk(); | ||
} | ||
} |