diff --git a/config/routes/tapi.yaml b/config/routes/tapi.yaml index fb343038..34d45650 100644 --- a/config/routes/tapi.yaml +++ b/config/routes/tapi.yaml @@ -16,6 +16,11 @@ tapi_jo_invoice: controller: App\Controller\TAPI\JobOrderController:getJOInvoice methods: [GET] +tapi_jo_cancel: + path: /tapi/job_order/cancel + controller: App\Controller\TAPI\JobOrderController:cancelJobOrder + methods: [POST] + # vehicle manufacturer and vehicle tapi_vehicle_mfg_list: path: /tapi/vehicle/mfgs diff --git a/src/Controller/TAPI/JobOrderController.php b/src/Controller/TAPI/JobOrderController.php index 3d38efd5..5b625b5d 100644 --- a/src/Controller/TAPI/JobOrderController.php +++ b/src/Controller/TAPI/JobOrderController.php @@ -528,41 +528,21 @@ class JobOrderController extends APIController 'jo_id', 'reason' ]; - $res = $this->checkParamsAndKey($req, $em, $required_params); - if ($res->isError()) - return $res->getReturnResponse(); + $msg = $this->checkRequiredParameters($req, $required_params); + if ($msg) + return new APIResponse(false, $msg); // get job order $jo_id = $req->request->get('jo_id'); $jo = $em->getRepository(JobOrder::class)->find($jo_id); if ($jo == null) { - $res->setError(true) - ->setErrorMessage('No job order found'); - return $res->getReturnResponse(); - } - - // get customer - // TODO: modify to get customer - $cust = $this->session->getCustomer(); - if ($cust == null) - { - $res->setError(true) - ->setErrorMessage('No customer information found'); - return $res->getReturnResponse(); - } - - // check that the customer owns the job order - $jo_cust = $jo->getCustomer(); - if ($jo_cust->getID() != $cust->getID()) - { - $res->setError(true) - ->setErrorMessage('Job order was not initiated by customer'); - return $res->getReturnResponse(); + $message = 'No job order found'; + return new APIResponse(false, $message); } // TODO: check job order status, if it's cancellable - $cancel_reason = $req->request->get('reason'); + $cancel_reason = $req->request->get('reason'); $jo->cancel($cancel_reason); @@ -584,10 +564,10 @@ class JobOrderController extends APIController ]; $mclient->sendRiderEvent($jo, $payload); + $data = []; + $message = 'Job order cancelled.'; - $res->setData([]); - - return $res->getReturnResponse(); + return new APIResponse(true, $message, $data); } // we can't use param converter for now because we want to output the proper 404