Have hub reassign and rider reassign send mqtt events to rider and user app #162
This commit is contained in:
parent
4b635631ba
commit
e3a0e8e23c
1 changed files with 35 additions and 3 deletions
|
|
@ -1489,7 +1489,7 @@ class JobOrderController extends BaseController
|
||||||
return $this->render('job-order/form.html.twig', $params);
|
return $this->render('job-order/form.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function openHubSubmit(Request $req, ValidatorInterface $validator, $id)
|
public function openHubSubmit(Request $req, ValidatorInterface $validator, MQTTClient $mclient, $id)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
|
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
|
||||||
|
|
||||||
|
|
@ -1522,7 +1522,17 @@ class JobOrderController extends BaseController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($error_array)) {
|
if (empty($error_array))
|
||||||
|
{
|
||||||
|
// rider mqtt event
|
||||||
|
// NOTE: need to send this before saving because rider will be cleared
|
||||||
|
$rider_payload = [
|
||||||
|
'event' => 'cancelled',
|
||||||
|
'reason' => 'Reassigned',
|
||||||
|
'jo_id' => $obj->getID(),
|
||||||
|
];
|
||||||
|
$mclient->sendRiderEvent($obj, $rider_payload);
|
||||||
|
|
||||||
// coordinates
|
// coordinates
|
||||||
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
|
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
|
||||||
|
|
||||||
|
|
@ -1571,6 +1581,12 @@ class JobOrderController extends BaseController
|
||||||
// validated! save the entity
|
// validated! save the entity
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
// user mqtt event
|
||||||
|
$payload = [
|
||||||
|
'event' => 'outlet_assign'
|
||||||
|
];
|
||||||
|
$mclient->sendEvent($obj, $payload);
|
||||||
|
|
||||||
// return successful response
|
// return successful response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'success' => 'Changes have been saved!'
|
'success' => 'Changes have been saved!'
|
||||||
|
|
@ -1615,7 +1631,7 @@ class JobOrderController extends BaseController
|
||||||
return $this->render('job-order/form.html.twig', $params);
|
return $this->render('job-order/form.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function openRiderSubmit(Request $req, ValidatorInterface $validator, $id)
|
public function openRiderSubmit(Request $req, ValidatorInterface $validator, MQTTClient $mclient, $id)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
|
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
|
||||||
|
|
||||||
|
|
@ -1648,6 +1664,15 @@ class JobOrderController extends BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($error_array)) {
|
if (empty($error_array)) {
|
||||||
|
// rider mqtt event
|
||||||
|
// NOTE: need to send this before saving because rider will be cleared
|
||||||
|
$rider_payload = [
|
||||||
|
'event' => 'cancelled',
|
||||||
|
'reason' => 'Reassigned',
|
||||||
|
'jo_id' => $obj->getID(),
|
||||||
|
];
|
||||||
|
$mclient->sendRiderEvent($obj, $rider_payload);
|
||||||
|
|
||||||
// coordinates
|
// coordinates
|
||||||
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
|
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
|
||||||
|
|
||||||
|
|
@ -1697,6 +1722,13 @@ class JobOrderController extends BaseController
|
||||||
// validated! save the entity
|
// validated! save the entity
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
// send event to mobile app
|
||||||
|
$payload = [
|
||||||
|
'event' => 'driver_assigned'
|
||||||
|
];
|
||||||
|
$mclient->sendEvent($obj, $payload);
|
||||||
|
$mclient->sendRiderEvent($obj, $payload);
|
||||||
|
|
||||||
// return successful response
|
// return successful response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'success' => 'Changes have been saved!'
|
'success' => 'Changes have been saved!'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue