Skip to content

Commit

Permalink
Merge pull request #800 from daveroverts/799-slot-edit-issue
Browse files Browse the repository at this point in the history
fix: fix for enums not properly working after
  • Loading branch information
daveroverts authored Mar 14, 2024
2 parents 33125b1 + 20c13a1 commit d8dff7b
Show file tree
Hide file tree
Showing 21 changed files with 1,104 additions and 1,048 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function verifyLogin(Request $request)
$booking = Booking::whereUuid(session('booking'))->first();
session()->forget('booking');
if (!empty($booking)) {
if ($booking->status !== BookingStatus::BOOKED->value) {
if ($booking->status != BookingStatus::BOOKED) {
return to_route('bookings.edit', $booking);
}
return to_route('bookings.show', $booking);
Expand Down
16 changes: 8 additions & 8 deletions app/Http/Controllers/Booking/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function show(Booking $booking): View
public function edit(Booking $booking): View|RedirectResponse
{
// Check if the booking has already been booked or reserved
if ($booking->status !== BookingStatus::UNASSIGNED->value) {
if ($booking->status != BookingStatus::UNASSIGNED) {
// Check if current user has booked/reserved
if ($booking->user_id == auth()->id()) {
if ($booking->status == BookingStatus::BOOKED->value && !$booking->is_editable) {
if ($booking->status == BookingStatus::BOOKED && !$booking->is_editable) {
flashMessage('info', __('Danger'), __('You cannot edit the booking!'));
return to_route('bookings.event.index', $booking->event);
}
Expand All @@ -49,7 +49,7 @@ public function edit(Booking $booking): View|RedirectResponse
return view('booking.edit', compact('booking', 'flight'));
} else {
// Check if the booking has already been reserved
if ($booking->status === BookingStatus::RESERVED->value) {
if ($booking->status == BookingStatus::RESERVED) {
flashMessage(
'danger',
__('Warning'),
Expand Down Expand Up @@ -96,7 +96,7 @@ public function edit(Booking $booking): View|RedirectResponse
->by(auth()->user())
->on($booking)
->log('Flight reserved');
$booking->status = BookingStatus::RESERVED->value;
$booking->status = BookingStatus::RESERVED;
$booking->user()->associate(auth()->user())->save();
flashMessage(
'info',
Expand Down Expand Up @@ -146,8 +146,8 @@ public function update(UpdateBooking $request, Booking $booking): RedirectRespon
);
}

$booking->status = BookingStatus::BOOKED->value;
if ($booking->getOriginal('status') === BookingStatus::RESERVED->value) {
if ($booking->status == BookingStatus::RESERVED) {
$booking->status = BookingStatus::BOOKED;
$booking->save();
event(new BookingConfirmed($booking));
if (!Str::contains(config('mail.default'), ['log', 'array'])) {
Expand Down Expand Up @@ -219,7 +219,7 @@ public function cancel(Booking $booking): RedirectResponse
]);
}

if ($booking->status === BookingStatus::BOOKED->value) {
if ($booking->status == BookingStatus::BOOKED) {
event(new BookingCancelled($booking, auth()->user()));
$title = __('Booking cancelled!');
$message = __('Booking has been cancelled!');
Expand All @@ -228,7 +228,7 @@ public function cancel(Booking $booking): RedirectResponse
$message = __('Slot is now free to use again');
}

$booking->status = BookingStatus::UNASSIGNED->value;
$booking->status = BookingStatus::UNASSIGNED;
flashMessage('info', $title, $message);
$booking->user()->dissociate()->save();
return to_route('bookings.event.index', $booking->event);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/EventCleanupReservationsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function handle(): void
->whereStatus(BookingStatus::RESERVED->value)
->each(function (Booking $booking) {
if (now()->greaterThanOrEqualTo($booking->updated_at->addMinutes(10))) {
$booking->status = BookingStatus::UNASSIGNED->value;
$booking->status = BookingStatus::UNASSIGNED;
$booking->user_id = null;
$booking->save();
}
Expand Down
18 changes: 11 additions & 7 deletions app/Models/Airport.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,33 @@
* @property string $icao
* @property string $iata
* @property string $name
* @property float|null $latitude
* @property float|null $longitude
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Event[] $eventArr
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Event> $eventArr
* @property-read int|null $event_arr_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Event[] $eventDep
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Event> $eventDep
* @property-read int|null $event_dep_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Flight[] $flightsArr
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Flight> $flightsArr
* @property-read int|null $flights_arr_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Flight[] $flightsDep
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Flight> $flightsDep
* @property-read int|null $flights_dep_count
* @property-read string $full_name
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AirportLink[] $links
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\AirportLink> $links
* @property-read int|null $links_count
* @method static \Database\Factories\AirportFactory factory(...$parameters)
* @method static \Database\Factories\AirportFactory factory($count = null, $state = [])
* @method static Builder|Airport newModelQuery()
* @method static Builder|Airport newQuery()
* @method static Builder|Airport query()
* @method static Builder|Airport whereCreatedAt($value)
* @method static Builder|Airport whereIata($value)
* @method static Builder|Airport whereIcao($value)
* @method static Builder|Airport whereId($value)
* @method static Builder|Airport whereLatitude($value)
* @method static Builder|Airport whereLongitude($value)
* @method static Builder|Airport whereName($value)
* @method static Builder|Airport whereUpdatedAt($value)
* @mixin \Eloquent
Expand Down
8 changes: 4 additions & 4 deletions app/Models/AirportLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read Airport|null $airport
* @property-read AirportLinkType|null $type
* @method static \Database\Factories\AirportLinkFactory factory(...$parameters)
* @property-read \App\Models\Airport|null $airport
* @property-read \App\Models\AirportLinkType|null $type
* @method static \Database\Factories\AirportLinkFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|AirportLink newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|AirportLink newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|AirportLink query()
Expand Down
4 changes: 2 additions & 2 deletions app/Models/AirportLinkType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* @property string|null $class
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read AirportLink $links
* @property-read \App\Models\AirportLink|null $links
* @method static Builder|AirportLinkType newModelQuery()
* @method static Builder|AirportLinkType newQuery()
* @method static Builder|AirportLinkType query()
Expand Down
18 changes: 10 additions & 8 deletions app/Models/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Enums\BookingStatus;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Spatie\Activitylog\LogOptions;
Expand All @@ -18,7 +19,7 @@
* @property int $id
* @property string|null $uuid
* @property int $event_id
* @property int $status
* @property BookingStatus $status
* @property bool $is_editable
* @property int|null $user_id
* @property string|null $callsign
Expand All @@ -27,20 +28,20 @@
* @property \Illuminate\Support\Carbon|null $final_information_email_sent_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read Airport|null $airportArr
* @property-read Airport|null $airportDep
* @property-read Event $event
* @property-read \Illuminate\Database\Eloquent\Collection|Flight[] $flights
* @property-read \App\Models\Airport|null $airportArr
* @property-read \App\Models\Airport|null $airportDep
* @property-read \App\Models\Event $event
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Flight> $flights
* @property-read int|null $flights_count
* @property-read string $formatted_actype
* @property-read string $formatted_callsign
* @property-read string $formatted_selcal
* @property-read bool $has_received_final_information_email
* @property-write mixed $actype
* @property-read User|null $user
* @method static \Database\Factories\BookingFactory factory(...$parameters)
* @property-read \App\Models\User|null $user
* @method static \Database\Factories\BookingFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Booking newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Booking newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Booking query()
Expand Down Expand Up @@ -68,6 +69,7 @@ class Booking extends Model
];

protected $casts = [
'status' => BookingStatus::class,
'is_editable' => 'boolean',
'has_already_received_final_information_email' => 'boolean',
'final_information_email_sent_at' => 'datetime',
Expand Down
10 changes: 5 additions & 5 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
* @property bool $is_oceanic_event
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read \App\Models\Airport|null $airportArr
* @property-read \App\Models\Airport|null $airportDep
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Booking[] $bookings
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Booking> $bookings
* @property-read int|null $bookings_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Faq[] $faqs
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Faq> $faqs
* @property-read int|null $faqs_count
* @property-read \Illuminate\Database\Eloquent\Collection|EventLink[] $links
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\EventLink> $links
* @property-read int|null $links_count
* @property-read \App\Models\EventType|null $type
* @method static \Database\Factories\EventFactory factory(...$parameters)
* @method static \Database\Factories\EventFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Event findSimilarSlugs(string $attribute, array $config, string $slug)
* @method static \Illuminate\Database\Eloquent\Builder|Event newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Event newQuery()
Expand Down
8 changes: 4 additions & 4 deletions app/Models/EventLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
* @property string $url
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read Event $event
* @property-read AirportLinkType $type
* @method static \Database\Factories\EventLinkFactory factory(...$parameters)
* @property-read \App\Models\Event $event
* @property-read \App\Models\AirportLinkType $type
* @method static \Database\Factories\EventLinkFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|EventLink newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|EventLink newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|EventLink query()
Expand Down
4 changes: 2 additions & 2 deletions app/Models/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*
* @property int $id
* @property string $name
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read Event $events
* @property-read \App\Models\Event|null $events
* @method static Builder|EventType newModelQuery()
* @method static Builder|EventType newQuery()
* @method static Builder|EventType query()
Expand Down
6 changes: 3 additions & 3 deletions app/Models/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* @property string $answer
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read \Illuminate\Database\Eloquent\Collection|Event[] $events
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Event> $events
* @property-read int|null $events_count
* @method static \Database\Factories\FaqFactory factory(...$parameters)
* @method static \Database\Factories\FaqFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Faq newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Faq newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Faq query()
Expand Down
10 changes: 5 additions & 5 deletions app/Models/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
* @property string|null $oceanicTrack
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read Airport $airportArr
* @property-read Airport $airportDep
* @property-read Booking $booking
* @property-read \App\Models\Airport $airportArr
* @property-read \App\Models\Airport $airportDep
* @property-read \App\Models\Booking $booking
* @property-read string $formatted_ctot
* @property-read string $formatted_eta
* @property-read string $formatted_notes
* @property-read string $formatted_oceanicfl
* @property-write mixed $oceanictrack
* @method static \Database\Factories\FlightFactory factory(...$parameters)
* @method static \Database\Factories\FlightFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Flight newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Flight newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Flight query()
Expand Down
12 changes: 7 additions & 5 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Enums\AirportView;
use Spatie\Activitylog\LogOptions;
use Illuminate\Notifications\Notifiable;
use App\Http\Controllers\OAuthController;
Expand All @@ -19,24 +20,24 @@
* @property string $name_last
* @property string $email
* @property bool $isAdmin
* @property int $airport_view
* @property AirportView $airport_view
* @property bool $use_monospace_font
* @property string|null $remember_token
* @property string|null $access_token
* @property string|null $refresh_token
* @property int|null $token_expires
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activities
* @property-read int|null $activities_count
* @property-read \Illuminate\Database\Eloquent\Collection|Booking[] $bookings
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Booking> $bookings
* @property-read int|null $bookings_count
* @property-read string $full_name
* @property-read string $pic
* @property-read \League\OAuth2\Client\Token\AccessToken|null $token
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
* @property-read int|null $notifications_count
* @method static \Database\Factories\UserFactory factory(...$parameters)
* @method static \Database\Factories\UserFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|User query()
Expand Down Expand Up @@ -80,6 +81,7 @@ class User extends Authenticatable
protected $casts = [
'isAdmin' => 'boolean',
'use_monospace_font' => 'boolean',
'airport_view' => AirportView::class,
];

public function getActivitylogOptions(): LogOptions
Expand Down
Loading

0 comments on commit d8dff7b

Please sign in to comment.