refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
55
app/Services/Contact/LifeEvent/DestroyLifeEvent.php
Normal file
55
app/Services/Contact/LifeEvent/DestroyLifeEvent.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Contact\LifeEvent;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Reminder;
|
||||
use App\Models\Contact\LifeEvent;
|
||||
|
||||
class DestroyLifeEvent extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'life_event_id' => 'required|integer',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a life event.
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(array $data): bool
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
$lifeEvent = LifeEvent::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['life_event_id']);
|
||||
|
||||
$lifeEvent->contact->throwInactive();
|
||||
|
||||
$this->deleteAssociatedReminder($lifeEvent);
|
||||
|
||||
$lifeEvent->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the associated reminder, if it's set.
|
||||
*/
|
||||
private function deleteAssociatedReminder($lifeEvent)
|
||||
{
|
||||
if ($lifeEvent->reminder_id) {
|
||||
Reminder::where('id', $lifeEvent->reminder_id)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user