Check if PIREP doesn't exist before cancelling

This commit is contained in:
Nabeel Shahzad 2022-02-16 19:13:47 -05:00
parent 08f82f8a2e
commit 648659aea5
2 changed files with 10 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -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');
}
/**