fix(helpdesk): inject appTitle/appUrl into HandoverNotificationService to avoid DB calls in tests
This commit is contained in:
@@ -145,7 +145,9 @@ final class HelpdeskContainerRegistrar implements ContainerRegistrar
|
||||
));
|
||||
|
||||
$container->set(HandoverNotificationService::class, static fn (AppContainer $c): HandoverNotificationService => new HandoverNotificationService(
|
||||
$c->get(MailService::class)
|
||||
$c->get(MailService::class),
|
||||
appTitle(),
|
||||
appUrl(),
|
||||
));
|
||||
|
||||
$container->set(HandoverService::class, static fn (AppContainer $c): HandoverService => new HandoverService(
|
||||
|
||||
@@ -8,9 +8,24 @@ class HandoverNotificationService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly MailService $mailService,
|
||||
private readonly string $appTitle = '',
|
||||
private readonly string $appUrl = '',
|
||||
) {
|
||||
}
|
||||
|
||||
private function resolveAppTitle(): string
|
||||
{
|
||||
return $this->appTitle !== '' ? $this->appTitle : appTitle();
|
||||
}
|
||||
|
||||
private function resolveAppUrl(string $path = ''): string
|
||||
{
|
||||
if ($this->appUrl !== '') {
|
||||
return rtrim($this->appUrl, '/') . ($path !== '' ? '/' . ltrim($path, '/') : '');
|
||||
}
|
||||
return appUrl($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the assignee that a handover was assigned to them.
|
||||
*
|
||||
@@ -29,7 +44,7 @@ class HandoverNotificationService
|
||||
$domainUrl = trim((string) ($handover['domain_url'] ?? ''));
|
||||
$dueDate = trim((string) ($handover['due_date'] ?? ''));
|
||||
$handoverId = (int) ($handover['id'] ?? 0);
|
||||
$handoverUrl = appUrl('helpdesk/handovers/edit/' . $handoverId);
|
||||
$handoverUrl = $this->resolveAppUrl('helpdesk/handovers/edit/' . $handoverId);
|
||||
|
||||
$vars = [
|
||||
'assignee_name' => $assigneeName,
|
||||
@@ -38,10 +53,10 @@ class HandoverNotificationService
|
||||
'domain_url' => $domainUrl !== '' ? $domainUrl : '—',
|
||||
'due_date' => $dueDate !== '' ? $dueDate : '—',
|
||||
'handover_url' => $handoverUrl,
|
||||
'app_name' => appTitle(),
|
||||
'app_name' => $this->resolveAppTitle(),
|
||||
];
|
||||
|
||||
$subject = sprintf('[%s] Ihnen wurde eine Übergabe zugewiesen', appTitle());
|
||||
$subject = sprintf('[%s] Ihnen wurde eine Übergabe zugewiesen', $this->resolveAppTitle());
|
||||
|
||||
$this->mailService->sendTemplate('handover_assigned', $vars, $toEmail, $subject);
|
||||
}
|
||||
@@ -69,7 +84,7 @@ class HandoverNotificationService
|
||||
$debitorName = trim((string) ($handover['debitor_name'] ?? ''));
|
||||
$domainUrl = trim((string) ($handover['domain_url'] ?? ''));
|
||||
$handoverId = (int) ($handover['id'] ?? 0);
|
||||
$handoverUrl = appUrl('helpdesk/handovers/edit/' . $handoverId);
|
||||
$handoverUrl = $this->resolveAppUrl('helpdesk/handovers/edit/' . $handoverId);
|
||||
|
||||
$vars = [
|
||||
'manager_name' => $managerName,
|
||||
@@ -77,10 +92,10 @@ class HandoverNotificationService
|
||||
'debitor_name' => $debitorName !== '' ? $debitorName : '—',
|
||||
'domain_url' => $domainUrl !== '' ? $domainUrl : '—',
|
||||
'handover_url' => $handoverUrl,
|
||||
'app_name' => appTitle(),
|
||||
'app_name' => $this->resolveAppTitle(),
|
||||
];
|
||||
|
||||
$subject = sprintf('[%s] Übergabe wurde zur Prüfung eingereicht', appTitle());
|
||||
$subject = sprintf('[%s] Übergabe wurde zur Prüfung eingereicht', $this->resolveAppTitle());
|
||||
|
||||
$this->mailService->sendTemplate('handover_review_requested', $vars, $toEmail, $subject);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user