added contact events

This commit is contained in:
Cihan Şentürk 2023-10-31 17:39:44 +03:00
parent 1ab7fec163
commit 67969d0710
9 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace App\Events\Common;
use App\Abstracts\Event;
use App\Models\Common\Contact;
class ContactCreated extends Event
{
public $contact;
/**
* Create a new event instance.
*
* @param $contact
*/
public function __construct(Contact $contact)
{
$this->contact = $contact;
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Events\Common;
use App\Abstracts\Event;
class ContactCreating extends Event
{
public $request;
/**
* Create a new event instance.
*
* @param $request
*/
public function __construct($request)
{
$this->request = $request;
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Events\Common;
use App\Abstracts\Event;
class ContactDeleted extends Event
{
public $contact;
/**
* Create a new event instance.
*
* @param $contact
*/
public function __construct($contact)
{
$this->contact = $contact;
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Events\Common;
use App\Abstracts\Event;
class ContactDeleting extends Event
{
public $contact;
/**
* Create a new event instance.
*
* @param $contact
*/
public function __construct($contact)
{
$this->contact = $contact;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Events\Common;
use App\Abstracts\Event;
use App\Models\Common\Contact;
class ContactUpdated extends Event
{
public $contact;
public $request;
/**
* Create a new event instance.
*
* @param $contact
* @param $request
*/
public function __construct(Contact $contact, $request)
{
$this->contact = $contact;
$this->request = $request;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Events\Common;
use App\Abstracts\Event;
use App\Models\Common\Contact;
class ContactUpdating extends Event
{
public $contact;
public $request;
/**
* Create a new event instance.
*
* @param $contact
* @param $request
*/
public function __construct(Contact $contact, $request)
{
$this->contact = $contact;
$this->request = $request;
}
}

View File

@ -3,6 +3,8 @@
namespace App\Jobs\Common;
use App\Abstracts\Job;
use App\Events\Common\ContactCreated;
use App\Events\Common\ContactCreating;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
@ -15,6 +17,8 @@ class CreateContact extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Contact
{
event(new ContactCreating($this->request));
\DB::transaction(function () {
if ($this->request->get('create_user', 'false') === 'true') {
$this->createUser();
@ -32,6 +36,8 @@ class CreateContact extends Job implements HasOwner, HasSource, ShouldCreate
$this->dispatch(new CreateContactPersons($this->model, $this->request));
});
event(new ContactCreated($this->model, $this->request));
return $this->model;
}

View File

@ -3,6 +3,8 @@
namespace App\Jobs\Common;
use App\Abstracts\Job;
use App\Events\Common\ContactDeleted;
use App\Events\Common\ContactDeleting;
use App\Interfaces\Job\ShouldDelete;
use App\Jobs\Auth\DeleteUser;
use App\Traits\Contacts;
@ -15,6 +17,8 @@ class DeleteContact extends Job implements ShouldDelete
{
$this->authorize();
event(new ContactDeleting($this->model));
\DB::transaction(function () {
$this->deleteRelationships($this->model, ['contact_persons']);
@ -25,6 +29,8 @@ class DeleteContact extends Job implements ShouldDelete
$this->model->delete();
});
event(new ContactDeleted($this->model));
return true;
}

View File

@ -3,6 +3,8 @@
namespace App\Jobs\Common;
use App\Abstracts\Job;
use App\Events\Common\ContactUpdated;
use App\Events\Common\ContactUpdating;
use App\Interfaces\Job\ShouldUpdate;
use App\Jobs\Auth\CreateUser;
use App\Jobs\Common\CreateContactPersons;
@ -15,6 +17,8 @@ class UpdateContact extends Job implements ShouldUpdate
{
$this->authorize();
event(new ContactUpdating($this->model, $this->request));
\DB::transaction(function () {
if ($this->request->get('create_user', 'false') === 'true') {
$this->createUser();
@ -40,6 +44,8 @@ class UpdateContact extends Job implements ShouldUpdate
$this->model->update($this->request->all());
});
event(new ContactUpdated($this->model, $this->request));
return $this->model;
}