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,34 +3,18 @@
namespace App\Jobs\Common;
use App\Abstracts\Job;
use App\Interfaces\Job\ShouldDelete;
class DeleteItem extends Job
class DeleteItem extends Job implements ShouldDelete
{
protected $item;
/**
* Create a new job instance.
*
* @param $item
*/
public function __construct($item)
{
$this->item = $item;
}
/**
* Execute the job.
*
* @return boolean|Exception
*/
public function handle()
public function handle(): bool
{
$this->authorize();
\DB::transaction(function () {
$this->deleteRelationships($this->item, ['taxes']);
$this->deleteRelationships($this->model, ['taxes']);
$this->item->delete();
$this->model->delete();
});
return true;
@ -38,25 +22,23 @@ class DeleteItem 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->item->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 = [
'invoice_items' => 'invoices',
'bill_items' => 'bills',
];
return $this->countRelationships($this->item, $rels);
return $this->countRelationships($this->model, $rels);
}
}