Files
KanbanGit/app/Actions/Notifications/QueueNotificationEventDeliveries.php
T
Koda ff5e54cad7
linter / quality (pull_request) Successful in 1m28s
tests / ci (8.4) (pull_request) Successful in 1m46s
Move notification event type onto events
2026-04-29 09:35:31 +00:00

44 lines
1.7 KiB
PHP

<?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();
$eventType = $event->eventType();
NotificationAction::query()
->enabled()
->where('project_id', $payload->projectId())
->where('event_type', $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' => $event->eventType(),
'notification_action_id' => $notificationAction->id,
'payload_metadata' => $payload->deliveryMetadata(),
])->id;
}
DeliverNotificationAction::dispatch(
notificationActionId: $notificationAction->id,
event: $event,
notificationDeliveryLogId: $notificationDeliveryLogId,
);
});
}
}