Add route for cancelJobOrder. Modify cancelJobOrder responses. #686
This commit is contained in:
parent
3e73bc0513
commit
4e613e3c01
2 changed files with 14 additions and 29 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue