Add jo perform rider api call for CMB #424

This commit is contained in:
Kendrick Chan 2020-06-20 16:38:08 +08:00
parent 131bc9c3f6
commit 943c01e5d9
5 changed files with 72 additions and 7 deletions

View file

@ -35,6 +35,11 @@ cmb_rapi_arrive:
controller: App\Controller\CMBRAPIController::arrive
methods: [POST]
cmb_rapi_performed:
path: /cmbrapi/joperform
controller: App\Controller\CMBRAPIController::performJobOrder
methods: [POST]
cmb_rapi_payment:
path: /cmbrapi/jopayment
controller: App\Controller\CMBRAPIController::payment

View file

@ -134,6 +134,26 @@ class CMBRAPIController extends Controller
return $res->getReturnResponse();
}
protected function generateResultFromHandler($data)
{
$res = new NewAPIResult();
if (isset($data['error']))
{
$message = $data['error'];
$title = $data['title'];
$res->setError(true)
->setErrorTitle($title)
->setErrorMessage($message);
}
else
{
$res->setData($data);
return $res;
}
public function cancelJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
{
$res = new NewAPIResult();
@ -183,6 +203,15 @@ class CMBRAPIController extends Controller
return $res->getReturnResponse();
}
public function performJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
{
$data = $rapi_handler->performJobOrder($req);
$res = $this->generateResultFromHandler($data);
return $res->getReturnResponse();
}
public function hubArrive(Request $req, RiderAPIHandlerInterface $rapi_handler)
{
$res = new NewAPIResult();

View file

@ -802,6 +802,11 @@ class JobOrder
$this->makeRiderAvailable();
}
public function perform()
{
$this->setStatus(JOStatus::PERFORM)
}
public function fulfill()
{
$this->setStatus(JOStatus::FULFILLED)

View file

@ -4,13 +4,15 @@ namespace App\Ramcar;
class JOStatus extends NameValue
{
const PENDING = 'pending'; // NOTE: JO has no hub assigned
const RIDER_ASSIGN = 'rider_assign'; // NOTE: JO has hub assigned but no rider assigned
const ASSIGNED = 'assigned'; // NOTE: JO has hub and rider assigned
const IN_TRANSIT = 'in_transit'; // NOTE: JO's rider is on his way
const IN_PROGRESS = 'in_progress'; // NOTE: JO fulfillment in progress
const CANCELLED = 'cancelled'; // NOTE: JO is cancelled
const FULFILLED = 'fulfilled'; // NOTE: JO is fulfilled
const PENDING = 'pending'; // JO has no hub assigned
const RIDER_ASSIGN = 'rider_assign'; // JO has hub assigned but no rider assigned
const ASSIGNED = 'assigned'; // JO has hub and rider assigned
const IN_TRANSIT = 'in_transit'; // JO's rider is on his way
const IN_PROGRESS = 'in_progress'; // JO fulfillment in progress
const PERFORMED = 'performed'; // Rider has finished performing JO task / service
const PAID = 'paid'; // Rider has finished collecting payment for JO
const CANCELLED = 'cancelled'; // JO is cancelled
const FULFILLED = 'fulfilled'; // JO is fulfilled
const COLLECTION = [
'pending' => 'For Dispatch',
@ -18,6 +20,8 @@ class JOStatus extends NameValue
'assigned' => 'Assigned',
'in_transit' => 'In Transit',
'in_progress' => 'In Progress',
'performed' => 'Service Performed',
'paid' => 'Customer Paid',
'cancelled' => 'Cancelled',
'fulfilled' => 'Completed',
];

View file

@ -801,6 +801,28 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
return $data;
}
public function performJobOrder(Request $req)
{
$required_params = [
'jo_id',
];
$data = $this->checkJO($req, $required_params, $jo);
if (isset($data['error']))
{
$data['title'] = 'Failed Job Order Perform';
return $data;
}
$jo->perform()
// TODO: make event for this?
$this->em->flush();
return $data;
}
public function rejectJobOrder(Request $req)
{
$required_params = [