-
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 #891 from bakaphp/development
v1.0-BETA21
- Loading branch information
Showing
38 changed files
with
1,084 additions
and
660 deletions.
There are no files selected for viewing
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
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
62 changes: 62 additions & 0 deletions
62
app/GraphQL/Guild/Mutations/Leads/LeadSourceManagementMutation.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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GraphQL\Guild\Mutations\Leads; | ||
|
||
use Kanvas\Apps\Models\Apps; | ||
use Kanvas\Companies\Repositories\CompaniesRepository; | ||
use Kanvas\Guild\Leads\Models\LeadType; | ||
use Kanvas\Guild\LeadSources\Actions\CreateLeadSourceAction; | ||
use Kanvas\Guild\LeadSources\DataTransferObject\LeadSource; | ||
use Kanvas\Guild\LeadSources\Models\LeadSource as LeadSourceModel; | ||
|
||
class LeadSourceManagementMutation | ||
{ | ||
public function create(mixed $root, array $request): LeadSourceModel | ||
{ | ||
$data = $this->validate($request['input']); | ||
|
||
$leadSource = LeadSource::from($data); | ||
|
||
return (new CreateLeadSourceAction($leadSource))->execute(); | ||
} | ||
|
||
public function update(mixed $root, array $request): LeadSourceModel | ||
{ | ||
$input = $this->validate($request['input']); | ||
|
||
$leadSource = LeadSourceModel::getByUuidFromCompanyApp( | ||
$request['id'], | ||
company:CompaniesRepository::getByUuid($input['companies_id']), | ||
app: app(Apps::class) | ||
); | ||
$leadSource->update([ | ||
'name' => $input['name'], | ||
'description' => $input['description'], | ||
'is_active' => $input['is_active'], | ||
'leads_types_id' => $input['leads_types_id'], | ||
]); | ||
|
||
return $leadSource; | ||
} | ||
|
||
public function delete(mixed $root, array $request): bool | ||
{ | ||
$leadSource = LeadSourceModel::getByUuidFromCompanyApp($request['id'], app: app(Apps::class)); | ||
CompaniesRepository::userAssociatedToCompany($leadSource->company, auth()->user()); | ||
|
||
return $leadSource->delete(); | ||
} | ||
|
||
public function validate(array $input): array | ||
{ | ||
$input['app'] = app(Apps::class); | ||
$input['company'] = CompaniesRepository::getByUuid($input['companies_id'], app: app(Apps::class), user: auth()->user()); | ||
CompaniesRepository::userAssociatedToCompany($input['company'], auth()->user()); | ||
$leadType = LeadType::getByUuidFromCompanyApp($input['leads_types_id'], company:$input['company'], app: app(Apps::class)); | ||
$input['leads_types_id'] = $leadType->getId(); | ||
|
||
return $input; | ||
} | ||
} |
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
Oops, something went wrong.