-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added is_flying Attribute to User Model #1729
base: dev
Are you sure you want to change the base?
Conversation
Based on feedback and conversations on discord. I added a isflying boolean.
@@ -25,6 +26,7 @@ | |||
* @property string callsign | |||
* @property string name | |||
* @property string name_private Only first name, rest are initials | |||
* @property bool is_flying |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should go in the bottom of the list where the properties are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And to in_flight
{ | ||
return Attribute::make( | ||
get: function ($_, $attrs) { | ||
return (bool) Pirep::where(['user_id' => $this->id, 'state' => PirepState::IN_PROGRESS])->count(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change this to use latest('updated_at')
. In case there is a bugged/old PIREP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the name also to inFlight()
. Since you're checking if they're in a particular state. Then the same property can probably be added to Aircraft
later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also, instead of count()
, use exists()
. Then you don't need to cast it. And you can add more constraints, to say in the last day, etc. But I think latest on when it's been modified should be ok. There will be ongoing updates to that record.
@BossOfGames is this still active? |
Even with the change you suggest @nabeelio , there is still a risk of getting false positives. If there are broken pireps in the database, this will always return true because of the state check in where clause 😞 To avoid this maybe we can use the user's latest pirep only and return the result according to it's state. At least this will recude the risk to a single pirep being broken or not. $pirep = Pirep::where('user_id' => $this->id)->latest('updated_at')->first();
return ($pirep->state === PirepState::IN_PROGRESS) ? true : false; Similar logic can be implemented for aircraft too (maybe with some new enums defined, like BOOKED, PLANNED etc.) And considering no replies since 5th March, I think OP does not follow or not interested in this change anymore. |
Based on feedback and conversations on discord. I added a isflying boolean.