PIREP tests working, using minutes to track flight hours instead of seconds
This commit is contained in:
@@ -38,7 +38,7 @@ class PIREPService extends BaseService
|
||||
*
|
||||
* @return Pirep
|
||||
*/
|
||||
public function create(Pirep &$pirep, array $field_values): Pirep
|
||||
public function create(Pirep $pirep, array $field_values=[]): Pirep
|
||||
{
|
||||
if($field_values === null) {
|
||||
$field_values = [];
|
||||
@@ -85,7 +85,7 @@ class PIREPService extends BaseService
|
||||
* @param int $new_status
|
||||
* @return Pirep
|
||||
*/
|
||||
public function changeStatus(Pirep &$pirep, int $new_status): Pirep
|
||||
public function changeStatus(Pirep $pirep, int $new_status): Pirep
|
||||
{
|
||||
Log::info('PIREP ' . $pirep->id . ' status change from '.$pirep->status.' to ' . $new_status);
|
||||
|
||||
@@ -127,7 +127,7 @@ class PIREPService extends BaseService
|
||||
* @param Pirep $pirep
|
||||
* @return Pirep
|
||||
*/
|
||||
public function accept(Pirep &$pirep): Pirep
|
||||
public function accept(Pirep $pirep): Pirep
|
||||
{
|
||||
# moving from a REJECTED state to ACCEPTED, reconcile statuses
|
||||
if ($pirep->status === config('enums.pirep_status.ACCEPTED')) {
|
||||
@@ -137,7 +137,7 @@ class PIREPService extends BaseService
|
||||
$ft = $pirep->flight_time;
|
||||
$pilot = $pirep->pilot;
|
||||
|
||||
$this->pilotSvc->adjustFlightHours($pilot, $ft);
|
||||
$this->pilotSvc->adjustFlightTime($pilot, $ft);
|
||||
$this->pilotSvc->adjustFlightCount($pilot, +1);
|
||||
$this->pilotSvc->calculatePilotRank($pilot);
|
||||
$pirep->pilot->refresh();
|
||||
@@ -160,7 +160,7 @@ class PIREPService extends BaseService
|
||||
* @param Pirep $pirep
|
||||
* @return Pirep
|
||||
*/
|
||||
public function reject(Pirep &$pirep): Pirep
|
||||
public function reject(Pirep $pirep): Pirep
|
||||
{
|
||||
# If this was previously ACCEPTED, then reconcile the flight hours
|
||||
# that have already been counted, etc
|
||||
@@ -168,7 +168,7 @@ class PIREPService extends BaseService
|
||||
$pilot = $pirep->pilot;
|
||||
$ft = $pirep->flight_time * -1;
|
||||
|
||||
$this->pilotSvc->adjustFlightHours($pilot, $ft);
|
||||
$this->pilotSvc->adjustFlightTime($pilot, $ft);
|
||||
$this->pilotSvc->adjustFlightCount($pilot, -1);
|
||||
$this->pilotSvc->calculatePilotRank($pilot);
|
||||
$pirep->pilot->refresh();
|
||||
|
||||
@@ -27,10 +27,10 @@ class UserService extends BaseService
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function adjustFlightHours(User $user, int $hours): User
|
||||
public function adjustFlightTime(User $user, int $minutes): User
|
||||
{
|
||||
$user->refresh();
|
||||
$user->flight_time += $hours;
|
||||
$user->flight_time += $minutes;
|
||||
$user->save();
|
||||
|
||||
event(new UserStateChanged($user));
|
||||
@@ -41,15 +41,10 @@ class UserService extends BaseService
|
||||
public function calculatePilotRank(User $user): User
|
||||
{
|
||||
$user->refresh();
|
||||
$pilot_hours = $user->flight_time / 3600;
|
||||
$pilot_hours = Utils::minutesToHours($user->flight_time);
|
||||
|
||||
# TODO: Cache
|
||||
$ranks = Cache::remember(
|
||||
config('cache.keys.RANKS_PILOT_LIST.key'),
|
||||
config('cache.keys.RANKS_PILOT_LIST.time'),
|
||||
function () {
|
||||
return Rank::where('auto_promote', true)->orderBy('hours', 'asc')->get();
|
||||
});
|
||||
$ranks = Rank::where('auto_promote', true)->orderBy('hours', 'asc')->get();
|
||||
|
||||
foreach ($ranks as $rank) {
|
||||
if($rank->hours > $pilot_hours) {
|
||||
|
||||
Reference in New Issue
Block a user