Files
NextChair/app/Services/Notifications/NotificationService.php
T
Stefan Lazic 2ef3654841
CI / ci (push) Canceled after 0s
PHP Rebuild
Initial PHP rebuild of the app
2026-09-05 08:21:33 +01:00

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;
}
}