Skip to content
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

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

BossOfGames
Copy link
Contributor

Based on feedback and conversations on discord. I added a isflying boolean.

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
Copy link
Owner

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

Copy link
Owner

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();
Copy link
Owner

@nabeelio nabeelio Dec 19, 2023

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.

Copy link
Owner

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.

Copy link
Owner

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.

@nabeelio
Copy link
Owner

nabeelio commented Mar 5, 2024

@BossOfGames is this still active?

@FatihKoz
Copy link
Contributor

FatihKoz commented Jul 15, 2024

I would change this to use latest('updated_at'). In case there is a bugged/old PIREP.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants