Merge branch '20-job-order-cancel-api' into 'master'
Resolve "Job order cancel API" Closes #20 See merge request jankstudio/resq!18
This commit is contained in:
commit
787eb32afd
3 changed files with 101 additions and 10 deletions
|
|
@ -89,3 +89,8 @@ api_rider_rating_add:
|
|||
path: /api/rider_rating
|
||||
controller: App\Controller\APIController::addRiderRating
|
||||
methods: [POST]
|
||||
|
||||
api_jo_cancel:
|
||||
path: /api/job_order/cancel
|
||||
controller: App\Controller\APIController:cancelJobOrder
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -1104,7 +1104,16 @@ class APIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
// TODO: check job order status if it's
|
||||
// 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();
|
||||
}
|
||||
|
||||
// TODO: check job order status, if it's complete
|
||||
|
||||
// add rider rating
|
||||
$rating_num = $req->request->get('rating');
|
||||
|
|
@ -1117,6 +1126,60 @@ class APIController extends Controller
|
|||
$em->persist($rating);
|
||||
$em->flush();
|
||||
|
||||
// TODO: set average rating in rider entity
|
||||
|
||||
$res->setData([]);
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function cancelJobOrder(Request $req)
|
||||
{
|
||||
$required_params = [
|
||||
'jo_id',
|
||||
'reason'
|
||||
];
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// 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
|
||||
$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();
|
||||
}
|
||||
|
||||
// TODO: check job order status, if it's cancellable
|
||||
|
||||
$jo->setStatus(JOStatus::CANCELLED)
|
||||
->setDateCancel(new DateTime())
|
||||
->setCancelReason($req->request->get('reason'));
|
||||
|
||||
$em->flush();
|
||||
|
||||
$res->setData([]);
|
||||
|
||||
return $res->getReturnResponse();
|
||||
|
|
|
|||
|
|
@ -167,6 +167,12 @@ class JobOrder
|
|||
*/
|
||||
protected $invoice;
|
||||
|
||||
// reason for cancel
|
||||
/**
|
||||
* @ORM\Column(type="string", length=200)
|
||||
*/
|
||||
protected $cancel_reason;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
|
@ -181,18 +187,12 @@ class JobOrder
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
public function setDateCreate($date_create)
|
||||
{
|
||||
$this->date_create = $date_create;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateCreate()
|
||||
{
|
||||
return $this->date_create;
|
||||
}
|
||||
|
||||
public function setDateSchedule($date_schedule)
|
||||
public function setDateSchedule(DateTime $date_schedule)
|
||||
{
|
||||
$this->date_schedule = $date_schedule;
|
||||
return $this;
|
||||
|
|
@ -203,7 +203,18 @@ class JobOrder
|
|||
return $this->date_schedule;
|
||||
}
|
||||
|
||||
public function setDateFulfill($date_fulfill)
|
||||
public function setDateCancel(DateTime $date_cancel)
|
||||
{
|
||||
$this->date_cancel = $date_cancel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateCancel()
|
||||
{
|
||||
return $this->date_cancel;
|
||||
}
|
||||
|
||||
public function setDateFulfill(DateTime $date_fulfill)
|
||||
{
|
||||
$this->date_fulfill = $date_fulfill;
|
||||
return $this;
|
||||
|
|
@ -214,7 +225,7 @@ class JobOrder
|
|||
return $this->date_fulfill;
|
||||
}
|
||||
|
||||
public function setDateAssign($date_assign)
|
||||
public function setDateAssign(DateTime $date_assign)
|
||||
{
|
||||
$this->date_assign = $date_assign;
|
||||
return $this;
|
||||
|
|
@ -359,6 +370,7 @@ class JobOrder
|
|||
|
||||
public function setStatus($status)
|
||||
{
|
||||
// TODO: validate status
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -412,4 +424,15 @@ class JobOrder
|
|||
{
|
||||
return $this->invoice;
|
||||
}
|
||||
|
||||
public function setCancelReason($reason)
|
||||
{
|
||||
$this->cancel_reason = $reason;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCancelReason()
|
||||
{
|
||||
return $this->cancel_reason;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue