Updated scheduled tasks
This commit is contained in:
@@ -232,8 +232,6 @@ class FlightController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate($this->rules());
|
||||
@@ -248,42 +246,10 @@ class FlightController extends Controller
|
||||
],
|
||||
]);
|
||||
|
||||
$this->notifyFollowersOnCreation($newFlight);
|
||||
|
||||
return redirect()->route('profile.departure-board', [Auth::user()->name, $newFlight->id]);
|
||||
}
|
||||
|
||||
protected function notifyFollowersOnCreation(UserFlight $flight): void
|
||||
{
|
||||
$user = $flight->user;
|
||||
$isFuture = $flight->departure_date->isFuture();
|
||||
|
||||
$title = $isFuture
|
||||
? "{$user->name} booked a new flight"
|
||||
: "{$user->name} logged a new flight";
|
||||
|
||||
|
||||
$flightNumber = $flight->flight_number ? "{$flight->flight_number} from" : 'From';
|
||||
$body = "{$flightNumber} {$flight->departureAirport->municipality} ({$flight->departureAirport->display_code}) → {$flight->arrivalAirport->municipality} ({$flight->arrivalAirport->display_code}) on {$flight->departure_date_display}";
|
||||
$url = route('profile.departure-board', [$user->name, $flight->id]);
|
||||
|
||||
$user->followers()->get()->each(function (User $follower) use ($title, $body, $url, $isFuture) {
|
||||
$notifyForFuture = $follower->getSetting('notify_on_upcoming_flight_added');
|
||||
$notifyForHistoric = $follower->getSetting('notify_on_historic_flight_added');
|
||||
|
||||
if (($isFuture && $notifyForFuture) || (!$isFuture && $notifyForHistoric)) {
|
||||
Notification::create([
|
||||
'user_id' => $follower->id,
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, UserFlight $flight)
|
||||
{
|
||||
@@ -323,36 +289,11 @@ class FlightController extends Controller
|
||||
],
|
||||
]);
|
||||
|
||||
if ($isFuture) {
|
||||
$this->notifyFollowersOnCancellation($flight);
|
||||
}
|
||||
|
||||
$flight->delete();
|
||||
|
||||
return redirect()->route('profile.'.$referrer, [Auth::user()->name]);
|
||||
}
|
||||
|
||||
protected function notifyFollowersOnCancellation(UserFlight $flight): void
|
||||
{
|
||||
$user = $flight->user;
|
||||
|
||||
$title = "{$user->name} cancelled a flight";
|
||||
$flightNumber = $flight->flight_number ? "{$flight->flight_number} from" : 'From';
|
||||
$body = "{$flightNumber} {$flight->departureAirport->municipality} ({$flight->departureAirport->display_code}) → {$flight->arrivalAirport->municipality} ({$flight->arrivalAirport->display_code}) on {$flight->departure_date_display}";
|
||||
$url = route('profile.view', [$user->name]);
|
||||
|
||||
$user->followers()->get()->each(function (User $follower) use ($title, $body, $url) {
|
||||
if ($follower->getSetting('notify_on_flight_cancellation')) {
|
||||
Notification::create([
|
||||
'user_id' => $follower->id,
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function staticData() : array {
|
||||
return [
|
||||
'seat_types' => SeatType::orderBy('id')->get()->toArray(),
|
||||
|
||||
Reference in New Issue
Block a user