Redirect correctly if not enough license seats exists to be checkout

This commit is contained in:
Ivan Nieto Vivanco 2022-09-20 18:55:53 -05:00
parent 9369165007
commit c32676596c

View file

@ -60,8 +60,10 @@ class LicenseCheckoutController extends Controller
$this->authorize('checkout', $license); $this->authorize('checkout', $license);
$licenseSeat = $this->findLicenseSeatToCheckout($license, $seatId); $licenseSeat = $this->findLicenseSeatToCheckout($license, $seatId);
dd($licenseSeat);
$licenseSeat->user_id = Auth::id(); $licenseSeat->user_id = Auth::id();
$checkoutMethod = 'checkoutTo'.ucwords(request('checkout_to_type')); $checkoutMethod = 'checkoutTo'.ucwords(request('checkout_to_type'));
if ($this->$checkoutMethod($licenseSeat)) { if ($this->$checkoutMethod($licenseSeat)) {
return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.checkout.success')); return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.checkout.success'));
@ -74,16 +76,21 @@ class LicenseCheckoutController extends Controller
{ {
$licenseSeat = LicenseSeat::find($seatId) ?? $license->freeSeat(); $licenseSeat = LicenseSeat::find($seatId) ?? $license->freeSeat();
if (! $licenseSeat) { if(is_null($licenseSeat)){
if ($seatId) { throw new \Illuminate\Http\Exceptions\HttpResponseException(redirect()->route('licenses.index')->with('error', 'This Seat is not available for checkout.'));
return redirect()->route('licenses.index')->with('error', 'This Seat is not available for checkout.');
} }
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license'); if (! $licenseSeat) {
if ($seatId) {
throw new \Illuminate\Http\Exceptions\HttpResponseException(redirect()->route('licenses.index')->with('error', 'This Seat is not available for checkout.'));
}
throw new \Illuminate\Http\Exceptions\HttpResponseException(redirect()->route('licenses.index')->with('error', 'There are no available seats for this license.'));
} }
if (! $licenseSeat->license->is($license)) { if (! $licenseSeat->license->is($license)) {
return redirect()->route('licenses.index')->with('error', 'The license seat provided does not match the license.'); throw new \Illuminate\Http\Exceptions\HttpResponseException(redirect()->route('licenses.index')->with('error', 'The license seat provided does not match the license.'));
} }
return $licenseSeat; return $licenseSeat;