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

@ -5,39 +5,23 @@ namespace App\Jobs\Common;
use App\Abstracts\Job;
use App\Exceptions\Common\LastDashboard;
use App\Exceptions\Common\NotUserDashboard;
use App\Interfaces\Job\ShouldDelete;
use App\Traits\Users;
class DeleteDashboard extends Job
class DeleteDashboard extends Job implements ShouldDelete
{
use Users;
protected $dashboard;
/**
* Create a new job instance.
*
* @param $dashboard
*/
public function __construct($dashboard)
{
$this->dashboard = $dashboard;
}
/**
* Execute the job.
*
* @return boolean
*/
public function handle()
public function handle(): bool
{
$this->authorize();
\DB::transaction(function () {
$this->deleteRelationships($this->dashboard, ['widgets']);
$this->deleteRelationships($this->model, ['widgets']);
$this->dashboard->users()->detach();
$this->model->users()->detach();
$this->dashboard->delete();
$this->model->delete();
});
return true;
@ -45,13 +29,11 @@ class DeleteDashboard extends Job
/**
* Determine if this action is applicable.
*
* @return void
*/
public function authorize()
public function authorize(): void
{
// Can't delete last dashboard for any shared user
foreach ($this->dashboard->users as $user) {
foreach ($this->model->users as $user) {
if ($user->dashboards()->enabled()->count() > 1) {
continue;
}
@ -62,7 +44,7 @@ class DeleteDashboard extends Job
}
// Check if user can access dashboard
if ($this->isNotUserDashboard($this->dashboard->id)) {
if ($this->isNotUserDashboard($this->model->id)) {
$message = trans('dashboards.error.not_user_dashboard');
throw new NotUserDashboard($message);