Skip to content

Commit 5bf1831

Browse files
committed
fix: SendEventFinalInformationNotification sending email to booked user
When triggering a test, a random booking is retrieved, and a email should be sent to the user that triggers the test. This however didn't happen. fix #405
1 parent 1426678 commit 5bf1831

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

app/Events/EventFinalInformation.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Events;
44

55
use App\Models\Booking;
6+
use App\Models\User;
67
use Illuminate\Broadcasting\Channel;
78
use Illuminate\Broadcasting\InteractsWithSockets;
89
use Illuminate\Broadcasting\PresenceChannel;
@@ -22,7 +23,7 @@ class EventFinalInformation
2223
*
2324
* @return void
2425
*/
25-
public function __construct(public Booking $booking, public $testMode = false)
26+
public function __construct(public Booking $booking, public ?User $testUser = null)
2627
{
2728
//
2829
}

app/Http/Controllers/Event/EventAdminController.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ public function sendFinalInformationMail(Request $request, Event $event): Redire
160160
->get();
161161

162162
if ($request->testmode) {
163-
event(new EventFinalInformation($bookings->random()));
163+
event(new EventFinalInformation($bookings->random(), $request->user()));
164+
164165
return response()->json(['success' => __('Email has been sent to yourself')]);
165166
} else {
166167
$count = $bookings->count();
@@ -184,6 +185,7 @@ public function sendFinalInformationMail(Request $request, Event $event): Redire
184185
->withProperty('count', $count)
185186
->log('Final Information E-mail');
186187
}
188+
187189
return redirect(route('admin.events.index'));
188190
}
189191

app/Listeners/SendEventFinalInformationNotification.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct()
2626
*/
2727
public function handle(EventFinalInformation $event)
2828
{
29-
if ($event->testMode) {
29+
if ($event->testUser) {
3030
activity()
3131
->by(auth()->user())
3232
->on($event->booking)
@@ -36,9 +36,12 @@ public function handle(EventFinalInformation $event)
3636
]
3737
)
3838
->log('Final Information E-mail test performed');
39-
} else {
40-
$event->booking->update(['final_information_email_sent_at' => now()]);
39+
40+
$event->testUser->notify(new \App\Notifications\EventFinalInformation($event->booking));
41+
return;
4142
}
43+
44+
$event->booking->update(['final_information_email_sent_at' => now()]);
4245
$event->booking->user->notify(new \App\Notifications\EventFinalInformation($event->booking));
4346
}
4447
}

0 commit comments

Comments
 (0)