added pointer interfaces for jobs

This commit is contained in:
Denis Duliçi
2021-09-06 11:53:57 +03:00
parent abd55133f1
commit c08a8cfc4e
63 changed files with 635 additions and 1524 deletions

View File

@@ -3,40 +3,24 @@
namespace App\Jobs\Common;
use App\Abstracts\Job;
use App\Interfaces\Job\ShouldDelete;
use App\Jobs\Auth\DeleteUser;
use App\Traits\Contacts;
class DeleteContact extends Job
class DeleteContact extends Job implements ShouldDelete
{
use Contacts;
protected $contact;
/**
* Create a new job instance.
*
* @param $contact
*/
public function __construct($contact)
{
$this->contact = $contact;
}
/**
* Execute the job.
*
* @return boolean|Exception
*/
public function handle()
public function handle() :bool
{
$this->authorize();
\DB::transaction(function () {
if ($user = $this->contact->user) {
if ($user = $this->model->user) {
$this->dispatch(new DeleteUser($user));
}
$this->contact->delete();
$this->model->delete();
});
return true;
@@ -44,19 +28,17 @@ class DeleteContact extends Job
/**
* Determine if this action is applicable.
*
* @return void
*/
public function authorize()
public function authorize(): void
{
if ($relationships = $this->getRelationships()) {
$message = trans('messages.warning.deleted', ['name' => $this->contact->name, 'text' => implode(', ', $relationships)]);
$message = trans('messages.warning.deleted', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
throw new \Exception($message);
}
}
public function getRelationships()
public function getRelationships(): array
{
$rels = [
'transactions' => 'transactions',
@@ -68,6 +50,6 @@ class DeleteContact extends Job
$rels['bills'] = 'bills';
}
return $this->countRelationships($this->contact, $rels);
return $this->countRelationships($this->model, $rels);
}
}