Refactor notification event payloads and listener naming
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Notifications;
|
||||
|
||||
use App\Enums\NotificationChannel;
|
||||
use App\Enums\NotificationDeliveryStatus;
|
||||
use App\Models\NotificationAction;
|
||||
use App\Models\NotificationDeliveryLog;
|
||||
|
||||
class QueueNotificationEventDeliveries
|
||||
{
|
||||
public function handle(NotificationEvent $event): void
|
||||
{
|
||||
$payload = $event->payload();
|
||||
|
||||
NotificationAction::query()
|
||||
->enabled()
|
||||
->where('project_id', $payload->projectId())
|
||||
->where('event_type', $payload->eventType()->value)
|
||||
->get(['channel', 'id'])
|
||||
->each(function (NotificationAction $notificationAction) use ($event, $payload): void {
|
||||
$notificationDeliveryLogId = null;
|
||||
|
||||
if (in_array($notificationAction->channel, [NotificationChannel::Discord, NotificationChannel::Webhook], true)) {
|
||||
$notificationDeliveryLogId = NotificationDeliveryLog::query()->create([
|
||||
'attempt_count' => 0,
|
||||
'channel' => $notificationAction->channel,
|
||||
'delivery_status' => NotificationDeliveryStatus::Pending,
|
||||
'event_type' => $payload->eventType(),
|
||||
'notification_action_id' => $notificationAction->id,
|
||||
'payload_metadata' => $payload->deliveryMetadata(),
|
||||
])->id;
|
||||
}
|
||||
|
||||
DeliverNotificationAction::dispatch(
|
||||
notificationActionId: $notificationAction->id,
|
||||
event: $event,
|
||||
notificationDeliveryLogId: $notificationDeliveryLogId,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user