feat: complete approval workflow
This commit is contained in:
77
app/Notifications/ReservationDecisionNotification.php
Normal file
77
app/Notifications/ReservationDecisionNotification.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Domain\Reservations\Models\Reservation;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class ReservationDecisionNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public readonly Reservation $reservation,
|
||||
public readonly string $event,
|
||||
public readonly ?string $comment = null,
|
||||
) {
|
||||
$this->afterCommit();
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail', 'database'];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$message = (new MailMessage)
|
||||
->subject($this->subject())
|
||||
->greeting("Atualização da requisição {$this->reservation->reference}")
|
||||
->line($this->message());
|
||||
|
||||
if (filled($this->comment)) {
|
||||
$message->line("Comentário: {$this->comment}");
|
||||
}
|
||||
|
||||
return $message->action('Consultar requisições', url('/requisicoes'));
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'reservation_uuid' => $this->reservation->uuid,
|
||||
'reference' => $this->reservation->reference,
|
||||
'event' => $this->event,
|
||||
'message' => $this->message(),
|
||||
'comment' => $this->comment,
|
||||
'url' => '/requisicoes',
|
||||
];
|
||||
}
|
||||
|
||||
private function subject(): string
|
||||
{
|
||||
return match ($this->event) {
|
||||
'approved' => "Requisição {$this->reservation->reference} aprovada",
|
||||
'rejected' => "Requisição {$this->reservation->reference} rejeitada",
|
||||
'information_requested' => "Esclarecimentos necessários para {$this->reservation->reference}",
|
||||
'asset_substituted' => "Equipamento alterado em {$this->reservation->reference}",
|
||||
default => "Atualização da requisição {$this->reservation->reference}",
|
||||
};
|
||||
}
|
||||
|
||||
private function message(): string
|
||||
{
|
||||
return match ($this->event) {
|
||||
'approved' => 'A sua requisição foi aprovada.',
|
||||
'rejected' => 'A sua requisição foi rejeitada.',
|
||||
'information_requested' => 'O aprovador pediu informações adicionais.',
|
||||
'asset_substituted' => 'Um equipamento da sua requisição foi substituído por outro equivalente.',
|
||||
default => 'O estado da sua requisição foi atualizado.',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user