Fix issue where user stats aren't incremented on PIREP auto accept (#335)
* Fix issue where user stats aren't incremented on PIREP auto accept * Formatting
This commit is contained in:
@@ -7,9 +7,6 @@ use App\Models\Flight;
|
||||
use App\Models\Rank;
|
||||
use App\Models\Subfleet;
|
||||
|
||||
/**
|
||||
* Class FleetService
|
||||
*/
|
||||
class FleetService extends Service
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ use App\Models\PirepFieldValue;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class PirepService
|
||||
@@ -181,6 +181,8 @@ class PirepService extends Service
|
||||
$pirep->submitted_at = Carbon::now('UTC');
|
||||
}
|
||||
|
||||
$pirep->status = PirepStatus::ARRIVED;
|
||||
|
||||
$pirep->save();
|
||||
$pirep->refresh();
|
||||
|
||||
@@ -213,10 +215,6 @@ class PirepService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
$pirep->state = $default_state;
|
||||
$pirep->status = PirepStatus::ARRIVED;
|
||||
$pirep->save();
|
||||
|
||||
Log::info('New PIREP filed', [$pirep]);
|
||||
event(new PirepFiled($pirep));
|
||||
|
||||
@@ -224,8 +222,12 @@ class PirepService extends Service
|
||||
if ($default_state === PirepState::ACCEPTED) {
|
||||
$pirep = $this->accept($pirep);
|
||||
$this->setPilotState($pirep->pilot, $pirep);
|
||||
} else {
|
||||
$pirep->state = $default_state;
|
||||
}
|
||||
|
||||
$pirep->save();
|
||||
|
||||
// Check the user state, set them to ACTIVE if on leave
|
||||
if ($pirep->user->state !== UserState::ACTIVE) {
|
||||
$old_state = $pirep->user->state;
|
||||
@@ -260,6 +262,8 @@ class PirepService extends Service
|
||||
* @param Pirep $pirep
|
||||
* @param int $new_state
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return Pirep
|
||||
*/
|
||||
public function changeState(Pirep $pirep, int $new_state)
|
||||
@@ -341,9 +345,6 @@ class PirepService extends Service
|
||||
|
||||
$pirep->refresh();
|
||||
|
||||
// Any ancillary tasks before an event is dispatched
|
||||
$this->removeBid($pirep);
|
||||
|
||||
$this->setPilotState($pilot, $pirep);
|
||||
event(new PirepAccepted($pirep));
|
||||
|
||||
|
||||
@@ -325,6 +325,9 @@ class UserService extends Service
|
||||
'state' => PirepState::ACCEPTED,
|
||||
];
|
||||
|
||||
$flight_count = Pirep::where($w)->count();
|
||||
$user->flights = $flight_count;
|
||||
|
||||
$flight_time = Pirep::where($w)->sum('flight_time');
|
||||
$user->flight_time = $flight_time;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user