modify booking response data
This commit is contained in:
@@ -15,6 +15,7 @@ use Modules\Booking\Enums\BookingChannel;
|
||||
use Modules\Booking\Http\Requests\StoreBookingRequest;
|
||||
use Modules\Booking\Http\Resources\BookingResource;
|
||||
use Modules\Booking\Models\Booking;
|
||||
use Modules\Payment\Enums\PaymentStatus;
|
||||
use Modules\Shared\Enums\VehicleOption;
|
||||
|
||||
class BookingController extends Controller
|
||||
@@ -50,6 +51,17 @@ class BookingController extends Controller
|
||||
}
|
||||
|
||||
$bookings = $query
|
||||
// Only bookings that actually have a completed payment — a
|
||||
// pending_payment booking never had money move, so it's noise
|
||||
// in a booking list, not a real reservation to show.
|
||||
->whereHas('payments', fn ($paymentQuery) => $paymentQuery->where('status', PaymentStatus::Completed))
|
||||
// A round trip is two Booking rows (outbound + return leg,
|
||||
// linked via linked_booking_id — domain.md §2b), but it should
|
||||
// still surface once here, not as two separate list entries.
|
||||
// The outbound row's `linked_booking` already carries the
|
||||
// return leg's full detail (including vehicle_options).
|
||||
->where('is_return_leg', false)
|
||||
->when($request->filled('booking_ref'), fn ($q) => $q->where('booking_ref', 'ilike', '%'.$request->string('booking_ref').'%'))
|
||||
->with(self::EAGER_LOADS)
|
||||
->latest()
|
||||
->paginate();
|
||||
|
||||
@@ -31,6 +31,15 @@ class BookingResource extends JsonResource
|
||||
'dropoff_lat' => $this->dropoff_lat,
|
||||
'dropoff_lng' => $this->dropoff_lng,
|
||||
'price' => $this->price,
|
||||
// This leg's own price, same value CancelBookingAction/
|
||||
// RefundBookingAction use for this specific leg. total_price is
|
||||
// the round-trip total (this leg + linked leg) — computed here,
|
||||
// not left to the client to sum, since it must always match what
|
||||
// InitiatePaymentAction actually charges (bcadd, same as there).
|
||||
// Equal to `price` for a plain one-way booking.
|
||||
'total_price' => $this->relationLoaded('linkedBooking') && $this->linkedBooking !== null
|
||||
? bcadd((string) $this->price, (string) $this->linkedBooking->price, 2)
|
||||
: $this->price,
|
||||
'created_by_channel' => $this->created_by_channel,
|
||||
// Only ever populated once status is confirmed — see AssignDriverAction.
|
||||
'driver_name' => $this->driver_name,
|
||||
@@ -82,6 +91,15 @@ class BookingResource extends JsonResource
|
||||
'line_total' => $selection->line_total,
|
||||
])
|
||||
: null,
|
||||
// Each leg gets its own independent driver/vehicle
|
||||
// assignment — the return leg is never guaranteed the same
|
||||
// car as the outbound leg (domain.md §2b). Only ever
|
||||
// populated once that leg's own status is confirmed — see
|
||||
// AssignDriverAction.
|
||||
'driver_name' => $this->linkedBooking->driver_name,
|
||||
'driver_phone' => $this->linkedBooking->driver_phone,
|
||||
'car_plate_number' => $this->linkedBooking->car_plate_number,
|
||||
'car_model' => $this->linkedBooking->car_model,
|
||||
]),
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user