MInor fixes

This commit is contained in:
David Bomba 2023-01-31 21:05:01 +11:00
parent 58e53aa961
commit f3e5682d11
13 changed files with 198 additions and 126 deletions

View File

@ -11,53 +11,34 @@
namespace App\Jobs\Util; namespace App\Jobs\Util;
use App\Jobs\Util\SystemLogger;
use App\Jobs\Util\WebhookSingle; use App\Jobs\Util\WebhookSingle;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Models\Client as ClientModel; use App\Models\Company;
use App\Models\SystemLog;
use App\Models\Webhook; use App\Models\Webhook;
use App\Transformers\ArraySerializer;
use App\Utils\Ninja; use App\Utils\Ninja;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use League\Fractal\Manager;
use League\Fractal\Resource\Item;
class WebhookHandler implements ShouldQueue class WebhookHandler implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $entity;
private $event_id;
private $company;
public $tries = 1; //number of retries public $tries = 1; //number of retries
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;
private string $includes;
/** /**
* Create a new job instance. * Create a new job instance.
* *
* @param $event_id * @param $event_id
* @param $entity * @param $entity
*/ */
public function __construct($event_id, $entity, $company, $includes = '') public function __construct(private int $event_id, private $entity, private Company $company, private string $includes = ''){}
{
$this->event_id = $event_id;
$this->entity = $entity;
$this->company = $company;
$this->includes = $includes;
}
/** /**
* Execute the job. * Execute the job.
@ -74,10 +55,10 @@ class WebhookHandler implements ShouldQueue
return true; return true;
} }
$subscriptions = Webhook::where('company_id', $this->company->id) Webhook::where('company_id', $this->company->id)
->where('event_id', $this->event_id) ->where('event_id', $this->event_id)
->cursor() ->cursor()
->each(function ($subscription) { ->each(function ($subscription) {
WebhookSingle::dispatch($subscription->id, $this->entity, $this->company->db, $this->includes); WebhookSingle::dispatch($subscription->id, $this->entity, $this->company->db, $this->includes);

View File

@ -51,5 +51,7 @@ class RestoreClientActivity implements ShouldQueue
$fields->activity_type_id = Activity::RESTORE_CLIENT; $fields->activity_type_id = Activity::RESTORE_CLIENT;
$this->activity_repo->save($fields, $event->client, $event->event_vars); $this->activity_repo->save($fields, $event->client, $event->event_vars);
return false;
} }
} }

View File

@ -17,6 +17,9 @@ use App\Models\Webhook;
class ClientObserver class ClientObserver
{ {
public $afterCommit = true;
/** /**
* Handle the client "created" event. * Handle the client "created" event.
* *
@ -30,7 +33,7 @@ class ClientObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client, $client->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client, $client->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -42,29 +45,43 @@ class ClientObserver
*/ */
public function updated(Client $client) public function updated(Client $client)
{ {
nlog("updated event {$client->id}");
$event = Webhook::EVENT_UPDATE_CLIENT;
if($client->is_deleted)
$event = Webhook::EVENT_DELETE_CLIENT; //this event works correctly.
$subscriptions = Webhook::where('company_id', $client->company->id) $subscriptions = Webhook::where('company_id', $client->company->id)
->where('event_id', Webhook::EVENT_UPDATE_CLIENT) ->where('event_id', $event)
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CLIENT, $client, $client->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch($event, $client, $client->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
/** /**
* Handle the client "deleted" event. * Handle the client "archived" event.
* *
* @param Client $client * @param Client $client
* @return void * @return void
*/ */
public function deleted(Client $client) public function deleted(Client $client)
{ {
if($client->is_deleted)
return;
nlog("deleted event {$client->id}");
$subscriptions = Webhook::where('company_id', $client->company->id) $subscriptions = Webhook::where('company_id', $client->company->id)
->where('event_id', Webhook::EVENT_DELETE_CLIENT) ->where('event_id', Webhook::EVENT_ARCHIVE_CLIENT)
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_CLIENT, $client, $client->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_CLIENT, $client, $client->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -76,7 +93,18 @@ class ClientObserver
*/ */
public function restored(Client $client) public function restored(Client $client)
{ {
// nlog("Restored {$client->id}");
$subscriptions = Webhook::where('company_id', $client->company->id)
->where('event_id', Webhook::EVENT_RESTORE_CLIENT)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_RESTORE_CLIENT, $client, $client->company)->delay(now()->addSeconds(rand(1,5)));
}
return false;
} }
/** /**

View File

@ -32,7 +32,7 @@ class CreditObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_CREATE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -49,7 +49,7 @@ class CreditObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -66,7 +66,7 @@ class CreditObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_DELETE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }

View File

@ -30,7 +30,7 @@ class ExpenseObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -47,7 +47,7 @@ class ExpenseObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -64,7 +64,7 @@ class ExpenseObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }

View File

@ -34,7 +34,7 @@ class InvoiceObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -51,7 +51,7 @@ class InvoiceObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -68,7 +68,7 @@ class InvoiceObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }

View File

@ -32,7 +32,7 @@ class ProjectObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_CREATE, $project, $project->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_PROJECT_CREATE, $project, $project->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -49,7 +49,7 @@ class ProjectObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_UPDATE, $project, $project->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_PROJECT_UPDATE, $project, $project->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -67,7 +67,7 @@ class ProjectObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_DELETE, $project, $project->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_PROJECT_DELETE, $project, $project->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }

View File

@ -32,7 +32,7 @@ class QuoteObserver
if ($subscriptions) { if ($subscriptions) {
$quote->load('client'); $quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -50,7 +50,7 @@ class QuoteObserver
if ($subscriptions) { if ($subscriptions) {
$quote->load('client'); $quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -68,7 +68,7 @@ class QuoteObserver
if ($subscriptions) { if ($subscriptions) {
$quote->load('client'); $quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(rand(1,5)));
} }
} }

View File

@ -30,7 +30,7 @@ class TaskObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task, $task->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task, $task->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -47,7 +47,7 @@ class TaskObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task, $task->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task, $task->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }
@ -64,7 +64,7 @@ class TaskObserver
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task, $task->company)->delay(now()->addSeconds(2)); WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task, $task->company)->delay(now()->addSeconds(rand(1,5)));
} }
} }

View File

@ -0,0 +1,93 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Observers;
use App\Jobs\Util\WebhookHandler;
use App\Models\Vendor;
use App\Models\Webhook;
class VendorObserver
{
/**
* Handle the vendor "created" event.
*
* @param Vendor $vendor
* @return void
*/
public function created(Vendor $vendor)
{
$subscriptions = Webhook::where('company_id', $vendor->company->id)
->where('event_id', Webhook::EVENT_CREATE_VENDOR)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_VENDOR, $vendor, $vendor->company)->delay(now()->addSeconds(rand(1,5)));
}
}
/**
* Handle the vendor "updated" event.
*
* @param Vendor $vendor
* @return void
*/
public function updated(Vendor $vendor)
{
$subscriptions = Webhook::where('company_id', $vendor->company->id)
->where('event_id', Webhook::EVENT_UPDATE_VENDOR)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_VENDOR, $vendor, $vendor->company)->delay(now()->addSeconds(rand(1,5)));
}
}
/**
* Handle the vendor "deleted" event.
*
* @param Vendor $vendor
* @return void
*/
public function deleted(Vendor $vendor)
{
$subscriptions = Webhook::where('company_id', $vendor->company->id)
->where('event_id', Webhook::EVENT_DELETE_VENDOR)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_VENDOR, $vendor, $vendor->company)->delay(now()->addSeconds(rand(1,5)));
}
}
/**
* Handle the vendor "restored" event.
*
* @param Vendor $vendor
* @return void
*/
public function restored(Vendor $vendor)
{
//
}
/**
* Handle the vendor "force deleted" event.
*
* @param Vendor $vendor
* @return void
*/
public function forceDeleted(Vendor $vendor)
{
//
}
}

View File

@ -241,6 +241,7 @@ use App\Models\Quote;
use App\Models\Subscription; use App\Models\Subscription;
use App\Models\Task; use App\Models\Task;
use App\Models\User; use App\Models\User;
use App\Models\Vendor;
use App\Models\VendorContact; use App\Models\VendorContact;
use App\Observers\AccountObserver; use App\Observers\AccountObserver;
use App\Observers\ClientContactObserver; use App\Observers\ClientContactObserver;
@ -258,9 +259,10 @@ use App\Observers\ProposalObserver;
use App\Observers\PurchaseOrderObserver; use App\Observers\PurchaseOrderObserver;
use App\Observers\QuoteObserver; use App\Observers\QuoteObserver;
use App\Observers\SubscriptionObserver; use App\Observers\SubscriptionObserver;
use App\Observers\VendorContactObserver;
use App\Observers\TaskObserver; use App\Observers\TaskObserver;
use App\Observers\UserObserver; use App\Observers\UserObserver;
use App\Observers\VendorContactObserver;
use App\Observers\VendorObserver;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Mail\Events\MessageSending; use Illuminate\Mail\Events\MessageSending;
use Illuminate\Mail\Events\MessageSent; use Illuminate\Mail\Events\MessageSent;
@ -651,6 +653,7 @@ class EventServiceProvider extends ServiceProvider
Quote::observe(QuoteObserver::class); Quote::observe(QuoteObserver::class);
Task::observe(TaskObserver::class); Task::observe(TaskObserver::class);
User::observe(UserObserver::class); User::observe(UserObserver::class);
Vendor::observe(VendorObserver::class);
VendorContact::observe(VendorContactObserver::class); VendorContact::observe(VendorContactObserver::class);
PurchaseOrder::observe(PurchaseOrderObserver::class); PurchaseOrder::observe(PurchaseOrderObserver::class);
} }

View File

@ -55,7 +55,7 @@ class BaseRepository
/** /**
* @param $entity * @param $entity
*/ */
public function archive($entity): void public function archive($entity)
{ {
if ($entity->trashed()) { if ($entity->trashed()) {
return; return;
@ -67,8 +67,9 @@ class BaseRepository
if (class_exists($className)) { if (class_exists($className)) {
event(new $className($entity, $entity->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new $className($entity, $entity->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
$this->handleWebhook($entity, false);
} }
// $this->handleWebhook($entity, 'ARCHIVE');
} }
/** /**
@ -87,109 +88,70 @@ class BaseRepository
if ($entity->is_deleted) { if ($entity->is_deleted) {
$fromDeleted = true; $fromDeleted = true;
$entity->is_deleted = false; $entity->is_deleted = false;
$entity->save(); $entity->saveQuietly();
} }
$className = $this->getEventClass($entity, 'Restored'); $className = $this->getEventClass($entity, 'Restored');
if (class_exists($className)) { if (class_exists($className)) {
event(new $className($entity, $fromDeleted, $entity->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new $className($entity, $fromDeleted, $entity->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
$this->handleWebhook($entity, true);
} }
// $this->handleWebhook($entity, 'RESTORE');
} }
private function handleWebhook($entity, $restore) private function handleWebhook($entity, $action): void
{ {
switch(true) { $includes = '';
$event = null;
switch($entity) {
case $entity instanceof Invoice: case $entity instanceof Invoice:
if ($restore){ $event = "EVENT_{$action}_INVOICE";
$webhookEvent = Webhook::EVENT_RESTORE_INVOICE; $includes = 'client';
}
else {
$webhookEvent = Webhook::EVENT_ARCHIVE_INVOICE;}
break; break;
case $entity instanceof Quote: case $entity instanceof Quote:
if ($restore){ $event = "EVENT_{$action}_QUOTE";
$webhookEvent = Webhook::EVENT_RESTORE_QUOTE; $includes = 'client';
}
else {
$webhookEvent = Webhook::EVENT_ARCHIVE_QUOTE;
}
break;
case $entity instanceof Credit: case $entity instanceof Credit:
if ($restore){ $event = "EVENT_{$action}_CREDIT";
$webhookEvent = Webhook::EVENT_RESTORE_CREDIT; $includes = 'client';
}
else {
$webhookEvent = Webhook::EVENT_ARCHIVE_CREDIT;}
break; break;
case $entity instanceof Payment: case $entity instanceof Payment:
if ($restore){ $event = "EVENT_{$action}_PAYMENT";
$webhookEvent = Webhook::EVENT_RESTORE_PAYMENT; $includes = 'invoices,client';
}
else {
$webhookEvent = Webhook::EVENT_ARCHIVE_PAYMENT;}
break; break;
case $entity instanceof Task: case $entity instanceof Task:
if ($restore){ $event = "EVENT_{$action}_TASK";
$webhookEvent = Webhook::EVENT_RESTORE_TASK; $includes = '';
}
else {
$webhookEvent = Webhook::EVENT_ARCHIVE_TASK;}
break; break;
case $entity instanceof Project: case $entity instanceof Project:
if ($restore){ $event = "EVENT_{$action}PROJECT";
$webhookEvent = Webhook::EVENT_RESTORE_PROJECT; $includes = 'client';
}
else {
$webhookEvent = Webhook::EVENT_ARCHIVE_PROJECT;}
break; break;
case $entity instanceof Client: case $entity instanceof Client:
if ($restore){ $event = "EVENT_{$action}_CLIENT";
$webhookEvent = Webhook::EVENT_RESTORE_CLIENT; $includes = '';
}
else{
$webhookEvent = Webhook::EVENT_ARCHIVE_CLIENT;
}
break; break;
case $entity instanceof Expense: case $entity instanceof Expense:
if ($restore){ $event = "EVENT_{$action}_EXPENSE";
$webhookEvent= Webhook::EVENT_RESTORE_EXPENSE; $includes = '';
}
else{
$webhookEvent = Webhook::EVENT_ARCHIVE_EXPENSE;
}
break; break;
case $entity instanceof Vendor: case $entity instanceof Vendor:
if ($restore){ $event = "EVENT_{$action}_VENDOR";
$webhookEvent = Webhook::EVENT_RESTORE_VENDOR; $includes = '';
}
else {
$webhookEvent = Webhook::EVENT_ARCHIVE_VENDOR;
}
break; break;
} }
if (isset($webhookEvent)){
if (isset($event)){
$subscriptions = Webhook::where('company_id', $entity->company_id) $subscriptions = Webhook::where('company_id', $entity->company_id)
->where('event_id', $webhookEvent) ->where('event_id', $event)
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions) {
switch(true){
case $webhookEvent == Webhook::EVENT_RESTORE_PAYMENT: WebhookHandler::dispatch($event, $entity, $entity->company, $includes)->delay(now()->addSeconds(rand(1,5)));
case $webhookEvent == Webhook::EVENT_ARCHIVE_PAYMENT:
WebhookHandler::dispatch($webhookEvent, $entity, $entity->company, 'invoices,client')->delay(now()->addSeconds(2));
break;
case $webhookEvent == Webhook::EVENT_RESTORE_EXPENSE:
case $webhookEvent == Webhook::EVENT_ARCHIVE_EXPENSE:
case $webhookEvent == Webhook::EVENT_ARCHIVE_CREDIT:
case $webhookEvent == Webhook::EVENT_RESTORE_CREDIT:
case $webhookEvent == Webhook::EVENT_RESTORE_CLIENT:
case $webhookEvent == Webhook::EVENT_ARCHIVE_CLIENT:
WebhookHandler::dispatch($webhookEvent, $entity, $entity->company)->delay(now()->addSeconds(2));
break;
default:
WebhookHandler::dispatch($webhookEvent, $entity, $entity->company, 'client')->delay(now()->addSeconds(2));
}
} }
} }

View File

@ -11,10 +11,13 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Repositories\ClientContactRepository;
use App\Repositories\ClientRepository;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Queue;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;