Updated scheduled tasks
This commit is contained in:
@@ -2,22 +2,18 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Notification;
|
||||
use App\Models\User;
|
||||
use App\Enums\FlightNotificationType;
|
||||
use App\Models\UserFlight;
|
||||
use App\Services\FollowerNotificationService;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
#[Signature('app:update-departed-flights')]
|
||||
#[Description('Command description')]
|
||||
class UpdateDepartedFlights extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$now = now()->utc();
|
||||
@@ -32,33 +28,7 @@ class UpdateDepartedFlights extends Command
|
||||
|
||||
foreach ($userFlights as $flight) {
|
||||
$flight->update(['departure_processed_at' => $now]);
|
||||
$this->notifyFollowersOnDeparture($flight);
|
||||
new FollowerNotificationService()->notifyFlightEvent($flight, FlightNotificationType::Departed);
|
||||
}
|
||||
}
|
||||
|
||||
protected function notifyFollowersOnDeparture(UserFlight $flight): void
|
||||
{
|
||||
$user = $flight->user;
|
||||
$title = "{$user->name} is taking off!";
|
||||
$flightNumber = $flight->flight_number ? "On {$flight->flight_number} from" : 'From';
|
||||
$body = "{$flightNumber} {$flight->departureAirport->municipality} → {$flight->arrivalAirport->municipality}";
|
||||
$url = route('profile.flight', [
|
||||
'user' => $user->id,
|
||||
'userFlight' => $flight->id,
|
||||
]);
|
||||
|
||||
$user->followers()->get()->each(function (User $follower) use ($title, $body, $url) {
|
||||
$notify = $follower->getSetting('notify_on_flight_departure');
|
||||
|
||||
if ($notify) {
|
||||
Notification::create([
|
||||
'user_id' => $follower->id,
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user