Add notification action foundation
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Notifications;
|
||||
|
||||
use App\Models\NotificationAction;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class StoreProjectNotificationAction
|
||||
{
|
||||
/**
|
||||
* @param array{
|
||||
* channel: mixed,
|
||||
* channel_configuration?: array<string, mixed>|null,
|
||||
* delivery_url: string,
|
||||
* enabled: bool,
|
||||
* event_type: mixed,
|
||||
* message_template?: string|null,
|
||||
* name: string
|
||||
* } $validated
|
||||
*/
|
||||
public function handle(Project $project, array $validated): NotificationAction
|
||||
{
|
||||
return $project->notificationActions()->create([
|
||||
'channel' => Arr::get($validated, 'channel'),
|
||||
'channel_configuration' => Arr::get($validated, 'channel_configuration') ?? [],
|
||||
'delivery_url' => trim((string) Arr::get($validated, 'delivery_url')),
|
||||
'enabled' => (bool) Arr::get($validated, 'enabled'),
|
||||
'event_type' => Arr::get($validated, 'event_type'),
|
||||
'message_template' => $this->normalizeMessageTemplate(Arr::get($validated, 'message_template')),
|
||||
'name' => trim((string) Arr::get($validated, 'name')),
|
||||
]);
|
||||
}
|
||||
|
||||
private function normalizeMessageTemplate(mixed $messageTemplate): ?string
|
||||
{
|
||||
if (! is_string($messageTemplate)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$messageTemplate = trim($messageTemplate);
|
||||
|
||||
return $messageTemplate === '' ? null : $messageTemplate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user