20 lines
991 B
PHP
20 lines
991 B
PHP
<?php
|
|
|
|
namespace App\Services\Notifications;
|
|
|
|
use App\Enums\{NotificationChannel, NotificationType};
|
|
use App\Models\{Business, Notification};
|
|
|
|
class NotificationService
|
|
{
|
|
public function create(Business $business, NotificationType $type, string $body, string $idempotencyKey, ?string $userId = null, ?string $customerId = null, ?string $appointmentId = null, ?string $deepLinkPath = null, ?string $subject = null): Notification
|
|
{
|
|
$notification = Notification::query()->firstOrCreate(
|
|
['idempotencyKey' => $idempotencyKey],
|
|
['businessId' => $business->id, 'recipientUserId' => $userId, 'recipientCustomerId' => $customerId, 'type' => $type, 'appointmentId' => $appointmentId, 'subject' => $subject, 'bodyText' => $body, 'deepLinkPath' => $deepLinkPath],
|
|
);
|
|
if ($userId) $notification->deliveries()->firstOrCreate(['channel' => NotificationChannel::InApp], ['status' => 'SENT', 'sentAt' => now()]);
|
|
return $notification;
|
|
}
|
|
}
|