wip
This commit is contained in:
parent
21046dde66
commit
433d12be91
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Toby\Domain\Actions\VacationRequest;
|
namespace Toby\Domain\Actions\VacationRequest;
|
||||||
|
|
||||||
use Toby\Domain\Enums\Role;
|
use Toby\Domain\Enums\Role;
|
||||||
use Toby\Domain\Notifications\VacationRequestApprovedNotification;
|
use Toby\Domain\Notifications\VacationRequestStatusChangedNotification;
|
||||||
use Toby\Domain\VacationRequestStateManager;
|
use Toby\Domain\VacationRequestStateManager;
|
||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
use Toby\Eloquent\Models\VacationRequest;
|
||||||
@ -34,9 +34,9 @@ class ApproveAction
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$user->notify(new VacationRequestApprovedNotification($vacationRequest, $user));
|
$user->notify(new VacationRequestStatusChangedNotification($vacationRequest, $user));
|
||||||
}
|
}
|
||||||
|
|
||||||
$vacationRequest->user->notify(new VacationRequestApprovedNotification($vacationRequest, $vacationRequest->user));
|
$vacationRequest->user->notify(new VacationRequestStatusChangedNotification($vacationRequest, $vacationRequest->user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Toby\Domain\Actions\VacationRequest;
|
namespace Toby\Domain\Actions\VacationRequest;
|
||||||
|
|
||||||
use Toby\Domain\Enums\Role;
|
use Toby\Domain\Enums\Role;
|
||||||
use Toby\Domain\Notifications\VacationRequestCancelledNotification;
|
use Toby\Domain\Notifications\VacationRequestStatusChangedNotification;
|
||||||
use Toby\Domain\VacationRequestStateManager;
|
use Toby\Domain\VacationRequestStateManager;
|
||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
use Toby\Eloquent\Models\VacationRequest;
|
||||||
@ -34,9 +34,9 @@ class CancelAction
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$user->notify(new VacationRequestCancelledNotification($vacationRequest, $user));
|
$user->notify(new VacationRequestStatusChangedNotification($vacationRequest, $user));
|
||||||
}
|
}
|
||||||
|
|
||||||
$vacationRequest->user->notify(new VacationRequestCancelledNotification($vacationRequest, $vacationRequest->user));
|
$vacationRequest->user->notify(new VacationRequestStatusChangedNotification($vacationRequest, $vacationRequest->user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Toby\Domain\Actions\VacationRequest;
|
namespace Toby\Domain\Actions\VacationRequest;
|
||||||
|
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Toby\Domain\Notifications\VacationRequestCreatedNotification;
|
||||||
use Toby\Domain\VacationDaysCalculator;
|
use Toby\Domain\VacationDaysCalculator;
|
||||||
use Toby\Domain\VacationRequestStateManager;
|
use Toby\Domain\VacationRequestStateManager;
|
||||||
use Toby\Domain\VacationTypeConfigRetriever;
|
use Toby\Domain\VacationTypeConfigRetriever;
|
||||||
@ -31,6 +32,7 @@ class CreateAction
|
|||||||
{
|
{
|
||||||
$vacationRequest = $this->createVacationRequest($data, $creator);
|
$vacationRequest = $this->createVacationRequest($data, $creator);
|
||||||
$this->handleCreatedVacationRequest($vacationRequest);
|
$this->handleCreatedVacationRequest($vacationRequest);
|
||||||
|
$this->notify($vacationRequest);
|
||||||
|
|
||||||
return $vacationRequest;
|
return $vacationRequest;
|
||||||
}
|
}
|
||||||
@ -88,4 +90,9 @@ class CreateAction
|
|||||||
|
|
||||||
$this->stateManager->approve($vacationRequest);
|
$this->stateManager->approve($vacationRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function notify(VacationRequest $vacationRequest): void
|
||||||
|
{
|
||||||
|
$vacationRequest->user->notify(new VacationRequestCreatedNotification($vacationRequest));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Toby\Domain\Actions\VacationRequest;
|
namespace Toby\Domain\Actions\VacationRequest;
|
||||||
|
|
||||||
use Toby\Domain\Enums\Role;
|
use Toby\Domain\Enums\Role;
|
||||||
use Toby\Domain\Notifications\VacationRequestRejectedNotification;
|
use Toby\Domain\Notifications\VacationRequestStatusChangedNotification;
|
||||||
use Toby\Domain\VacationRequestStateManager;
|
use Toby\Domain\VacationRequestStateManager;
|
||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
use Toby\Eloquent\Models\VacationRequest;
|
||||||
@ -31,9 +31,9 @@ class RejectAction
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$user->notify(new VacationRequestRejectedNotification($vacationRequest, $user));
|
$user->notify(new VacationRequestStatusChangedNotification($vacationRequest, $user));
|
||||||
}
|
}
|
||||||
|
|
||||||
$vacationRequest->user->notify(new VacationRequestRejectedNotification($vacationRequest, $vacationRequest->user));
|
$vacationRequest->user->notify(new VacationRequestStatusChangedNotification($vacationRequest, $vacationRequest->user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Toby\Domain\Actions\VacationRequest;
|
namespace Toby\Domain\Actions\VacationRequest;
|
||||||
|
|
||||||
use Toby\Domain\Enums\Role;
|
use Toby\Domain\Enums\Role;
|
||||||
use Toby\Domain\Notifications\VacationRequestWaitsForAdminApprovalNotification;
|
use Toby\Domain\Notifications\VacationRequestWaitsForApprovalNotification;
|
||||||
use Toby\Domain\VacationRequestStateManager;
|
use Toby\Domain\VacationRequestStateManager;
|
||||||
use Toby\Domain\VacationTypeConfigRetriever;
|
use Toby\Domain\VacationTypeConfigRetriever;
|
||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
@ -33,7 +33,7 @@ class WaitForAdminApprovalAction
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$user->notify(new VacationRequestWaitsForAdminApprovalNotification($vacationRequest, $user));
|
$user->notify(new VacationRequestWaitsForApprovalNotification($vacationRequest, $user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Toby\Domain\Actions\VacationRequest;
|
namespace Toby\Domain\Actions\VacationRequest;
|
||||||
|
|
||||||
use Toby\Domain\Enums\Role;
|
use Toby\Domain\Enums\Role;
|
||||||
use Toby\Domain\Notifications\VacationRequestWaitsForTechApprovalNotification;
|
use Toby\Domain\Notifications\VacationRequestWaitsForApprovalNotification;
|
||||||
use Toby\Domain\VacationRequestStateManager;
|
use Toby\Domain\VacationRequestStateManager;
|
||||||
use Toby\Domain\VacationTypeConfigRetriever;
|
use Toby\Domain\VacationTypeConfigRetriever;
|
||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
@ -33,7 +33,7 @@ class WaitForTechApprovalAction
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$user->notify(new VacationRequestWaitsForTechApprovalNotification($vacationRequest, $user));
|
$user->notify(new VacationRequestWaitsForApprovalNotification($vacationRequest, $user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Toby\Domain\Notifications;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
|
||||||
use Illuminate\Notifications\Notification;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Toby\Eloquent\Models\User;
|
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
|
||||||
|
|
||||||
class VacationRequestCancelledNotification extends Notification
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
protected VacationRequest $vacationRequest,
|
|
||||||
protected User $user,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function via(): array
|
|
||||||
{
|
|
||||||
return ["mail"];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function toMail(): MailMessage
|
|
||||||
{
|
|
||||||
$url = route(
|
|
||||||
"vacation.requests.show",
|
|
||||||
[
|
|
||||||
"vacationRequest" => $this->vacationRequest,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->buildMailMessage($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildMailMessage(string $url): MailMessage
|
|
||||||
{
|
|
||||||
$user = $this->user->first_name;
|
|
||||||
$title = $this->vacationRequest->name;
|
|
||||||
$type = $this->vacationRequest->type->label();
|
|
||||||
$from = $this->vacationRequest->from->toDisplayString();
|
|
||||||
$to = $this->vacationRequest->to->toDisplayString();
|
|
||||||
$days = $this->vacationRequest->vacations()->count();
|
|
||||||
$requester = $this->vacationRequest->user->fullName;
|
|
||||||
|
|
||||||
return (new MailMessage())
|
|
||||||
->greeting(__("Hi :user!", [
|
|
||||||
"user" => $user,
|
|
||||||
]))
|
|
||||||
->subject(__("Vacation request :title has been cancelled", [
|
|
||||||
"title" => $title,
|
|
||||||
]))
|
|
||||||
->line(__("The vacation request :title for user :requester has been cancelled.", [
|
|
||||||
"title" => $title,
|
|
||||||
"requester" => $requester,
|
|
||||||
]))
|
|
||||||
->line(__("Vacation type: :type", [
|
|
||||||
"type" => $type,
|
|
||||||
]))
|
|
||||||
->line(__("From :from to :to (number of days: :days)", [
|
|
||||||
"from" => $from,
|
|
||||||
"to" => $to,
|
|
||||||
"days" => $days,
|
|
||||||
]))
|
|
||||||
->action(__("Click here for details"), $url);
|
|
||||||
}
|
|
||||||
}
|
|
@ -40,24 +40,17 @@ class VacationRequestCreatedNotification extends Notification
|
|||||||
protected function buildMailMessage(string $url): MailMessage
|
protected function buildMailMessage(string $url): MailMessage
|
||||||
{
|
{
|
||||||
$user = $this->vacationRequest->user->first_name;
|
$user = $this->vacationRequest->user->first_name;
|
||||||
$title = $this->vacationRequest->name;
|
|
||||||
$type = $this->vacationRequest->type->label();
|
$type = $this->vacationRequest->type->label();
|
||||||
$from = $this->vacationRequest->from->toDisplayString();
|
$from = $this->vacationRequest->from->toDisplayString();
|
||||||
$to = $this->vacationRequest->to->toDisplayString();
|
$to = $this->vacationRequest->to->toDisplayString();
|
||||||
$days = $this->vacationRequest->vacations()->count();
|
$days = $this->vacationRequest->vacations()->count();
|
||||||
$appName = config("app.name");
|
|
||||||
|
|
||||||
return (new MailMessage())
|
return (new MailMessage())
|
||||||
->greeting(__("Hi :user!", [
|
->greeting(__("Hi :user!", [
|
||||||
"user" => $user,
|
"user" => $user,
|
||||||
]))
|
]))
|
||||||
->subject(__("Vacation request :title has been created", [
|
->subject($this->buildSubject())
|
||||||
"title" => $title,
|
->line($this->buildDescription())
|
||||||
]))
|
|
||||||
->line(__("The vacation request :title has been created correctly in the :appName.", [
|
|
||||||
"title" => $title,
|
|
||||||
"appName" => $appName,
|
|
||||||
]))
|
|
||||||
->line(__("Vacation type: :type", [
|
->line(__("Vacation type: :type", [
|
||||||
"type" => $type,
|
"type" => $type,
|
||||||
]))
|
]))
|
||||||
@ -68,4 +61,38 @@ class VacationRequestCreatedNotification extends Notification
|
|||||||
]))
|
]))
|
||||||
->action(__("Click here for details"), $url);
|
->action(__("Click here for details"), $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function buildSubject(): string
|
||||||
|
{
|
||||||
|
$name = $this->vacationRequest->name;
|
||||||
|
|
||||||
|
if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) {
|
||||||
|
return __("Vacation request :title has been created", [
|
||||||
|
"title" => $name,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return __("Vacation request :title has been created on your behalf", [
|
||||||
|
"title" => $name,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildDescription(): string
|
||||||
|
{
|
||||||
|
$name = $this->vacationRequest->name;
|
||||||
|
$appName = config("app.name");
|
||||||
|
|
||||||
|
if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) {
|
||||||
|
return __("The vacation request :title has been created correctly in the :appName.", [
|
||||||
|
"title" => $name,
|
||||||
|
"appName" => $appName,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return __("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
|
||||||
|
"title" => $this->vacationRequest->name,
|
||||||
|
"appName" => $appName,
|
||||||
|
"creator" => $this->vacationRequest->creator->fullName,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Toby\Domain\Notifications;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
|
||||||
use Illuminate\Notifications\Notification;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
|
||||||
|
|
||||||
class VacationRequestCreatedOnEmployeeBehalf extends Notification
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
protected VacationRequest $vacationRequest,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function via(): array
|
|
||||||
{
|
|
||||||
return ["mail"];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function toMail(): MailMessage
|
|
||||||
{
|
|
||||||
$url = route(
|
|
||||||
"vacation.requests.show",
|
|
||||||
[
|
|
||||||
"vacationRequest" => $this->vacationRequest,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
return $this->buildMailMessage($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildMailMessage(string $url): MailMessage
|
|
||||||
{
|
|
||||||
$creator = $this->vacationRequest->creator->fullName;
|
|
||||||
$user = $this->vacationRequest->user->first_name;
|
|
||||||
$title = $this->vacationRequest->name;
|
|
||||||
$type = $this->vacationRequest->type->label();
|
|
||||||
$from = $this->vacationRequest->from->toDisplayString();
|
|
||||||
$to = $this->vacationRequest->to->toDisplayString();
|
|
||||||
$days = $this->vacationRequest->vacations()->count();
|
|
||||||
$appName = config("app.name");
|
|
||||||
|
|
||||||
return (new MailMessage())
|
|
||||||
->greeting(__("Hi :user!", [
|
|
||||||
"user" => $user,
|
|
||||||
]))
|
|
||||||
->subject(__("Vacation request :title has been created on your behalf", [
|
|
||||||
"title" => $title,
|
|
||||||
]))
|
|
||||||
->line(__("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
|
|
||||||
"title" => $title,
|
|
||||||
"appName" => $appName,
|
|
||||||
"creator" => $creator,
|
|
||||||
]))
|
|
||||||
->line(__("Vacation type: :type", [
|
|
||||||
"type" => $type,
|
|
||||||
]))
|
|
||||||
->line(__("From :from to :to (number of days: :days)", [
|
|
||||||
"from" => $from,
|
|
||||||
"to" => $to,
|
|
||||||
"days" => $days,
|
|
||||||
]))
|
|
||||||
->action(__("Click here for details"), $url);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Toby\Domain\Notifications;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
|
||||||
use Illuminate\Notifications\Notification;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Toby\Eloquent\Models\User;
|
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
|
||||||
|
|
||||||
class VacationRequestRejectedNotification extends Notification
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
protected VacationRequest $vacationRequest,
|
|
||||||
protected User $user,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function via(): array
|
|
||||||
{
|
|
||||||
return ["mail"];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function toMail(): MailMessage
|
|
||||||
{
|
|
||||||
$url = route(
|
|
||||||
"vacation.requests.show",
|
|
||||||
[
|
|
||||||
"vacationRequest" => $this->vacationRequest,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->buildMailMessage($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildMailMessage(string $url): MailMessage
|
|
||||||
{
|
|
||||||
$user = $this->user->first_name;
|
|
||||||
$title = $this->vacationRequest->name;
|
|
||||||
$type = $this->vacationRequest->type->label();
|
|
||||||
$from = $this->vacationRequest->from->toDisplayString();
|
|
||||||
$to = $this->vacationRequest->to->toDisplayString();
|
|
||||||
$days = $this->vacationRequest->vacations()->count();
|
|
||||||
$requester = $this->vacationRequest->user->fullName;
|
|
||||||
|
|
||||||
return (new MailMessage())
|
|
||||||
->greeting(__("Hi :user!", [
|
|
||||||
"user" => $user,
|
|
||||||
]))
|
|
||||||
->subject(__("Vacation request :title has been rejected", [
|
|
||||||
"title" => $title,
|
|
||||||
]))
|
|
||||||
->line(__("The vacation request :title for user :requester has been rejected.", [
|
|
||||||
"title" => $title,
|
|
||||||
"requester" => $requester,
|
|
||||||
]))
|
|
||||||
->line(__("Vacation type: :type", [
|
|
||||||
"type" => $type,
|
|
||||||
]))
|
|
||||||
->line(__("From :from to :to (number of days: :days)", [
|
|
||||||
"from" => $from,
|
|
||||||
"to" => $to,
|
|
||||||
"days" => $days,
|
|
||||||
]))
|
|
||||||
->action(__("Click here for details"), $url);
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ use InvalidArgumentException;
|
|||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
use Toby\Eloquent\Models\VacationRequest;
|
||||||
|
|
||||||
class VacationRequestApprovedNotification extends Notification
|
class VacationRequestStatusChangedNotification extends Notification
|
||||||
{
|
{
|
||||||
use Queueable;
|
use Queueable;
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ class VacationRequestApprovedNotification extends Notification
|
|||||||
$user = $this->user->first_name;
|
$user = $this->user->first_name;
|
||||||
$title = $this->vacationRequest->name;
|
$title = $this->vacationRequest->name;
|
||||||
$type = $this->vacationRequest->type->label();
|
$type = $this->vacationRequest->type->label();
|
||||||
|
$status = $this->vacationRequest->state;
|
||||||
$from = $this->vacationRequest->from->toDisplayString();
|
$from = $this->vacationRequest->from->toDisplayString();
|
||||||
$to = $this->vacationRequest->to->toDisplayString();
|
$to = $this->vacationRequest->to->toDisplayString();
|
||||||
$days = $this->vacationRequest->vacations()->count();
|
$days = $this->vacationRequest->vacations()->count();
|
||||||
@ -54,12 +55,14 @@ class VacationRequestApprovedNotification extends Notification
|
|||||||
->greeting(__("Hi :user!", [
|
->greeting(__("Hi :user!", [
|
||||||
"user" => $user,
|
"user" => $user,
|
||||||
]))
|
]))
|
||||||
->subject(__("Vacation request :title has been approved", [
|
->subject(__("Vacation request :title has been :status", [
|
||||||
"title" => $title,
|
"title" => $title,
|
||||||
|
"status" => $status,
|
||||||
]))
|
]))
|
||||||
->line(__("The vacation request :title for user :requester has been approved.", [
|
->line(__("The vacation request :title for user :requester has been :status.", [
|
||||||
"title" => $title,
|
"title" => $title,
|
||||||
"requester" => $requester,
|
"requester" => $requester,
|
||||||
|
"status" => $status,
|
||||||
]))
|
]))
|
||||||
->line(__("Vacation type: :type", [
|
->line(__("Vacation type: :type", [
|
||||||
"type" => $type,
|
"type" => $type,
|
@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Toby\Domain\Notifications;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
|
||||||
use Illuminate\Notifications\Notification;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Toby\Eloquent\Models\User;
|
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
|
||||||
|
|
||||||
class VacationRequestWaitsForAdminApprovalNotification extends Notification
|
|
||||||
{
|
|
||||||
use Queueable;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
protected VacationRequest $vacationRequest,
|
|
||||||
protected User $user,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function via(): array
|
|
||||||
{
|
|
||||||
return ["mail"];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function toMail(): MailMessage
|
|
||||||
{
|
|
||||||
$url = route(
|
|
||||||
"vacation.requests.show",
|
|
||||||
[
|
|
||||||
"vacationRequest" => $this->vacationRequest,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->buildMailMessage($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildMailMessage(string $url): MailMessage
|
|
||||||
{
|
|
||||||
$user = $this->user->first_name;
|
|
||||||
$requester = $this->vacationRequest->user->fullName;
|
|
||||||
$title = $this->vacationRequest->name;
|
|
||||||
$type = $this->vacationRequest->type->label();
|
|
||||||
$from = $this->vacationRequest->from->toDisplayString();
|
|
||||||
$to = $this->vacationRequest->to->toDisplayString();
|
|
||||||
$days = $this->vacationRequest->vacations()->count();
|
|
||||||
|
|
||||||
return (new MailMessage())
|
|
||||||
->greeting(__("Hi :user!", [
|
|
||||||
"user" => $user,
|
|
||||||
]))
|
|
||||||
->subject(__("Vacation request :title is waiting for your approval", [
|
|
||||||
"title" => $title,
|
|
||||||
]))
|
|
||||||
->line(__("The vacation request :title from user: :requester is waiting for your approval.", [
|
|
||||||
"title" => $title,
|
|
||||||
"requester" => $requester,
|
|
||||||
]))
|
|
||||||
->line(__("Vacation type: :type", [
|
|
||||||
"type" => $type,
|
|
||||||
]))
|
|
||||||
->line(__("From :from to :to (number of days: :days)", [
|
|
||||||
"from" => $from,
|
|
||||||
"to" => $to,
|
|
||||||
"days" => $days,
|
|
||||||
]))
|
|
||||||
->action(__("Click here for details"), $url);
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ use InvalidArgumentException;
|
|||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
use Toby\Eloquent\Models\VacationRequest;
|
||||||
|
|
||||||
class VacationRequestWaitsForTechApprovalNotification extends Notification
|
class VacationRequestWaitsForApprovalNotification extends Notification
|
||||||
{
|
{
|
||||||
use Queueable;
|
use Queueable;
|
||||||
|
|
@ -6,6 +6,8 @@ namespace Tests\Feature;
|
|||||||
|
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Bus;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Inertia\Testing\AssertableInertia as Assert;
|
use Inertia\Testing\AssertableInertia as Assert;
|
||||||
use Tests\FeatureTestCase;
|
use Tests\FeatureTestCase;
|
||||||
use Toby\Domain\Enums\VacationType;
|
use Toby\Domain\Enums\VacationType;
|
||||||
@ -29,6 +31,9 @@ class VacationRequestTest extends FeatureTestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
Bus::fake();
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
$this->polishHolidaysRetriever = $this->app->make(PolishHolidaysRetriever::class);
|
$this->polishHolidaysRetriever = $this->app->make(PolishHolidaysRetriever::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ use Toby\Domain\Actions\VacationRequest\RejectAction;
|
|||||||
use Toby\Domain\Actions\VacationRequest\WaitForTechApprovalAction;
|
use Toby\Domain\Actions\VacationRequest\WaitForTechApprovalAction;
|
||||||
use Toby\Domain\Enums\Role;
|
use Toby\Domain\Enums\Role;
|
||||||
use Toby\Domain\Enums\VacationType;
|
use Toby\Domain\Enums\VacationType;
|
||||||
use Toby\Domain\Notifications\VacationRequestRejectedNotification;
|
use Toby\Domain\Notifications\VacationRequestStatusChangedNotification;
|
||||||
use Toby\Domain\Notifications\VacationRequestWaitsForTechApprovalNotification;
|
use Toby\Domain\Notifications\VacationRequestWaitsForApprovalNotification;
|
||||||
use Toby\Domain\States\VacationRequest\Created;
|
use Toby\Domain\States\VacationRequest\Created;
|
||||||
use Toby\Domain\States\VacationRequest\WaitingForTechnical;
|
use Toby\Domain\States\VacationRequest\WaitingForTechnical;
|
||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
@ -68,8 +68,8 @@ class VacationRequestNotificationTest extends TestCase
|
|||||||
|
|
||||||
$waitForTechApprovalAction->execute($vacationRequest);
|
$waitForTechApprovalAction->execute($vacationRequest);
|
||||||
|
|
||||||
Notification::assertSentTo([$technicalApprover, $admin], VacationRequestWaitsForTechApprovalNotification::class);
|
Notification::assertSentTo([$technicalApprover, $admin], VacationRequestWaitsForApprovalNotification::class);
|
||||||
Notification::assertNotSentTo([$user, $administrativeApprover], VacationRequestWaitsForTechApprovalNotification::class);
|
Notification::assertNotSentTo([$user, $administrativeApprover], VacationRequestWaitsForApprovalNotification::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotificationIsSentOnceToUser(): void
|
public function testNotificationIsSentOnceToUser(): void
|
||||||
@ -104,7 +104,7 @@ class VacationRequestNotificationTest extends TestCase
|
|||||||
|
|
||||||
$rejectAction->execute($vacationRequest, $technicalApprover);
|
$rejectAction->execute($vacationRequest, $technicalApprover);
|
||||||
|
|
||||||
Notification::assertSentTo([$technicalApprover, $admin, $administrativeApprover], VacationRequestRejectedNotification::class);
|
Notification::assertSentTo([$technicalApprover, $admin, $administrativeApprover], VacationRequestStatusChangedNotification::class);
|
||||||
Notification::assertTimesSent(3,VacationRequestRejectedNotification::class);
|
Notification::assertTimesSent(3,VacationRequestStatusChangedNotification::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user