update api register

This commit is contained in:
Wian Drs
2026-08-01 11:42:42 +07:00
parent b0d08211ec
commit 75342dc7b7
55 changed files with 2254 additions and 35 deletions
@@ -40,12 +40,17 @@ class NotificationManager
}
return DB::transaction(function () use ($event, $recipient, $subject, $payload, $occurrenceKey, $context, $tenantId) {
$recipientOccurrenceKey = Str::limit(
$occurrenceKey.'|'.$recipient->getMorphClass().'|'.$recipient->getKey(),
255,
''
);
$occurrence = NotificationEventOccurrence::firstOrCreate([
'tenant_id' => $tenantId,
'notification_event_id' => $event->id,
'subjectable_type' => $subject->getMorphClass(),
'subjectable_id' => $subject->getKey(),
'occurrence_key' => $occurrenceKey,
'occurrence_key' => $recipientOccurrenceKey,
]);
if (! $occurrence->wasRecentlyCreated) {
return null;
@@ -57,6 +62,20 @@ class NotificationManager
->where('enabled', true)
->orderBy('priority')
->get();
$systemConfigured = NotificationPreference::where('tenant_id', $tenantId)
->where('notification_event_id', $event->id)
->where('channel', 'system')
->exists();
if (! $systemConfigured && in_array('system', $event->available_channels ?? [], true)) {
$preferences->prepend(new NotificationPreference([
'tenant_id' => $tenantId,
'notification_event_id' => $event->id,
'channel' => 'system',
'enabled' => true,
'priority' => 1,
'send_delay_minutes' => 0,
]));
}
if ($preferences->isEmpty()) {
$occurrence->update(['processed_at' => now()]);