From 648659aea5c2dca5227743d5554bc115dddd9273 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Wed, 16 Feb 2022 19:13:47 -0500 Subject: [PATCH] Check if PIREP doesn't exist before cancelling --- app/Contracts/Controller.php | 9 +++++---- app/Http/Controllers/Api/PirepController.php | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Contracts/Controller.php b/app/Contracts/Controller.php index b491006b..6f1ee8c1 100755 --- a/app/Contracts/Controller.php +++ b/app/Contracts/Controller.php @@ -87,16 +87,17 @@ abstract class Controller extends \Illuminate\Routing\Controller * * @return \Illuminate\Http\JsonResponse */ - public function message($message, $count = null) + public function message($message, $count = null, $attrs = []) { - $attrs = [ + $ret = [ 'message' => $message, + 'attrs' => $attrs, ]; if ($count !== null) { - $attrs['count'] = $count; + $ret['count'] = $count; } - return response()->json($attrs); + return response()->json($ret); } } diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index fcfb0ac6..12094314 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -334,16 +334,18 @@ class PirepController extends Controller * * @throws \Prettus\Validator\Exceptions\ValidatorException * - * @return PirepResource + * @return mixed */ public function cancel($pirep_id, Request $request) { Log::info('PIREP '.$pirep_id.' Cancel, user '.Auth::id(), $request->post()); $pirep = Pirep::find($pirep_id); - $this->pirepSvc->cancel($pirep); + if (!empty($pirep)) { + $this->pirepSvc->cancel($pirep); + } - return new PirepResource($pirep); + return $this->message('PIREP '.$pirep_id.' cancelled'); } /**