feat: complete approval workflow
This commit is contained in:
55
app/Notifications/ReservationSubmittedNotification.php
Normal file
55
app/Notifications/ReservationSubmittedNotification.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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 ReservationSubmittedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public readonly Reservation $reservation,
|
||||
public readonly string $event = 'submitted',
|
||||
) {
|
||||
$this->afterCommit();
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail', 'database'];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject($this->event === 'information_provided'
|
||||
? "Resposta recebida para {$this->reservation->reference}"
|
||||
: "Nova requisição {$this->reservation->reference}")
|
||||
->greeting($this->event === 'information_provided'
|
||||
? 'O requisitante respondeu ao pedido de esclarecimentos'
|
||||
: 'Nova requisição para aprovação')
|
||||
->line("{$this->reservation->requester->name} submeteu a requisição {$this->reservation->reference} para decisão.")
|
||||
->line("Período: {$this->reservation->starts_at->format('d/m/Y H:i')} — {$this->reservation->ends_at->format('d/m/Y H:i')}.")
|
||||
->action('Analisar requisição', url('/aprovacoes'));
|
||||
}
|
||||
|
||||
/** @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->event === 'information_provided'
|
||||
? "Foram prestados esclarecimentos para {$this->reservation->reference}."
|
||||
: "Nova requisição {$this->reservation->reference} aguarda decisão.",
|
||||
'url' => '/aprovacoes',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user