Move notification event type onto events
This commit is contained in:
@@ -245,7 +245,7 @@ class DeliverNotificationAction implements ShouldQueue
|
||||
'attempt_count' => 0,
|
||||
'channel' => $notificationAction->channel,
|
||||
'delivery_status' => NotificationDeliveryStatus::Pending,
|
||||
'event_type' => $this->event->payload()->eventType(),
|
||||
'event_type' => $this->event->eventType(),
|
||||
'notification_action_id' => $notificationAction->id,
|
||||
'payload_metadata' => $this->payloadMetadata(),
|
||||
]);
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace App\Actions\Notifications;
|
||||
|
||||
use App\Enums\NotificationEventType;
|
||||
|
||||
interface NotificationEvent
|
||||
{
|
||||
public function eventType(): NotificationEventType;
|
||||
|
||||
public function payload(): NotificationEventPayload;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Actions\Notifications;
|
||||
|
||||
use App\Enums\NotificationEventType;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
/**
|
||||
@@ -10,8 +9,6 @@ use Illuminate\Contracts\Support\Arrayable;
|
||||
*/
|
||||
interface NotificationEventPayload extends Arrayable
|
||||
{
|
||||
public function eventType(): NotificationEventType;
|
||||
|
||||
public function projectId(): int;
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,11 +12,12 @@ class QueueNotificationEventDeliveries
|
||||
public function handle(NotificationEvent $event): void
|
||||
{
|
||||
$payload = $event->payload();
|
||||
$eventType = $event->eventType();
|
||||
|
||||
NotificationAction::query()
|
||||
->enabled()
|
||||
->where('project_id', $payload->projectId())
|
||||
->where('event_type', $payload->eventType()->value)
|
||||
->where('event_type', $eventType->value)
|
||||
->get(['channel', 'id'])
|
||||
->each(function (NotificationAction $notificationAction) use ($event, $payload): void {
|
||||
$notificationDeliveryLogId = null;
|
||||
@@ -26,7 +27,7 @@ class QueueNotificationEventDeliveries
|
||||
'attempt_count' => 0,
|
||||
'channel' => $notificationAction->channel,
|
||||
'delivery_status' => NotificationDeliveryStatus::Pending,
|
||||
'event_type' => $payload->eventType(),
|
||||
'event_type' => $event->eventType(),
|
||||
'notification_action_id' => $notificationAction->id,
|
||||
'payload_metadata' => $payload->deliveryMetadata(),
|
||||
])->id;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Actions\Notifications;
|
||||
|
||||
use App\Enums\NotificationEventType;
|
||||
use Illuminate\Contracts\Events\ShouldDispatchAfterCommit;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
|
||||
@@ -13,6 +14,11 @@ final readonly class TicketCreated implements NotificationEvent, ShouldDispatchA
|
||||
public TicketCreatedPayload $payload,
|
||||
) {}
|
||||
|
||||
public function eventType(): NotificationEventType
|
||||
{
|
||||
return NotificationEventType::TicketCreate;
|
||||
}
|
||||
|
||||
public function payload(): NotificationEventPayload
|
||||
{
|
||||
return $this->payload;
|
||||
|
||||
@@ -7,8 +7,6 @@ use Carbon\CarbonImmutable;
|
||||
|
||||
final readonly class TicketCreatedPayload implements NotificationEventPayload
|
||||
{
|
||||
public NotificationEventType $eventType;
|
||||
|
||||
public ?int $fromStatusId;
|
||||
|
||||
public ?string $fromStatusLabel;
|
||||
@@ -27,16 +25,10 @@ final readonly class TicketCreatedPayload implements NotificationEventPayload
|
||||
public string $toStatusLabel,
|
||||
public CarbonImmutable $occurredAt,
|
||||
) {
|
||||
$this->eventType = NotificationEventType::TicketCreate;
|
||||
$this->fromStatusId = null;
|
||||
$this->fromStatusLabel = null;
|
||||
}
|
||||
|
||||
public function eventType(): NotificationEventType
|
||||
{
|
||||
return $this->eventType;
|
||||
}
|
||||
|
||||
public function projectId(): int
|
||||
{
|
||||
return $this->projectId;
|
||||
@@ -84,7 +76,7 @@ final readonly class TicketCreatedPayload implements NotificationEventPayload
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'event_type' => $this->eventType->value,
|
||||
'event_type' => NotificationEventType::TicketCreate->value,
|
||||
'project' => [
|
||||
'id' => $this->projectId,
|
||||
'key' => $this->projectKey,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Actions\Notifications;
|
||||
|
||||
use App\Enums\NotificationEventType;
|
||||
use Illuminate\Contracts\Events\ShouldDispatchAfterCommit;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
|
||||
@@ -13,6 +14,11 @@ final readonly class TicketStatusChanged implements NotificationEvent, ShouldDis
|
||||
public TicketStatusChangedPayload $payload,
|
||||
) {}
|
||||
|
||||
public function eventType(): NotificationEventType
|
||||
{
|
||||
return NotificationEventType::TicketStatusChanged;
|
||||
}
|
||||
|
||||
public function payload(): NotificationEventPayload
|
||||
{
|
||||
return $this->payload;
|
||||
|
||||
@@ -7,8 +7,6 @@ use Carbon\CarbonImmutable;
|
||||
|
||||
final readonly class TicketStatusChangedPayload implements NotificationEventPayload
|
||||
{
|
||||
public NotificationEventType $eventType;
|
||||
|
||||
public function __construct(
|
||||
public int $projectId,
|
||||
public string $projectKey,
|
||||
@@ -24,14 +22,7 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
|
||||
public int $toStatusId,
|
||||
public string $toStatusLabel,
|
||||
public CarbonImmutable $occurredAt,
|
||||
) {
|
||||
$this->eventType = NotificationEventType::TicketStatusChanged;
|
||||
}
|
||||
|
||||
public function eventType(): NotificationEventType
|
||||
{
|
||||
return $this->eventType;
|
||||
}
|
||||
) {}
|
||||
|
||||
public function projectId(): int
|
||||
{
|
||||
@@ -80,7 +71,7 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'event_type' => $this->eventType->value,
|
||||
'event_type' => NotificationEventType::TicketStatusChanged->value,
|
||||
'project' => [
|
||||
'id' => $this->projectId,
|
||||
'key' => $this->projectKey,
|
||||
|
||||
Reference in New Issue
Block a user