Modify capi user checking. #617
This commit is contained in:
parent
62c78939a8
commit
b5218a3499
1 changed files with 167 additions and 172 deletions
|
|
@ -46,6 +46,7 @@ use DateTime;
|
||||||
// third party API for rider
|
// third party API for rider
|
||||||
class RiderAppController extends APIController
|
class RiderAppController extends APIController
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
public function register(Request $req, EntityManagerInterface $em, RedisClientProvider $redis)
|
public function register(Request $req, EntityManagerInterface $em, RedisClientProvider $redis)
|
||||||
{
|
{
|
||||||
// confirm parameters
|
// confirm parameters
|
||||||
|
|
@ -117,7 +118,7 @@ class RiderAppController extends APIController
|
||||||
];
|
];
|
||||||
|
|
||||||
return new APIResponse(true, 'Rider API user created.', $data);
|
return new APIResponse(true, 'Rider API user created.', $data);
|
||||||
}
|
} */
|
||||||
|
|
||||||
public function login(Request $req, EntityManagerInterface $em, EncoderFactoryInterface $ef,
|
public function login(Request $req, EntityManagerInterface $em, EncoderFactoryInterface $ef,
|
||||||
RiderCache $rcache, RiderTracker $rider_tracker, MQTTClient $mclient,
|
RiderCache $rcache, RiderTracker $rider_tracker, MQTTClient $mclient,
|
||||||
|
|
@ -128,12 +129,14 @@ class RiderAppController extends APIController
|
||||||
|
|
||||||
// TODO: right now, no validation at all. Accept anything.
|
// TODO: right now, no validation at all. Accept anything.
|
||||||
// get capi user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
$capi_user = $em->getRepository(APIUser::class)->find($capi_user_id);
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// get rider id from capi user metadata
|
// get rider id from capi user metadata
|
||||||
// TODO: uncomment once getMetadata is available
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
// $rider_id = $capi_user->getMetadata();
|
if ($rider == null)
|
||||||
|
return new APIResponse(false, 'No rider found.');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$missing = $this->checkMissingParameters($req, $required_params);
|
$missing = $this->checkMissingParameters($req, $required_params);
|
||||||
|
|
@ -239,22 +242,22 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
|
return new APIResponse(false, 'No rider found.');
|
||||||
|
|
||||||
// make rider unavailable
|
// make rider unavailable
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
$rider->setAvailable(false);
|
$rider->setAvailable(false);
|
||||||
|
|
||||||
// remove from cache
|
// remove from cache
|
||||||
$rcache->removeActiveRider($rider->getID());
|
$rcache->removeActiveRider($rider->getID());
|
||||||
|
|
||||||
// remove rider from session
|
|
||||||
$rapi_session->setRider(null);
|
|
||||||
|
|
||||||
// TODO: log rider logging out
|
// TODO: log rider logging out
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
@ -281,17 +284,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
// do we have a job order?
|
// do we have a job order?
|
||||||
$jo = $rider->getActiveJobOrder();
|
$jo = $rider->getActiveJobOrder();
|
||||||
|
|
@ -402,17 +403,15 @@ class RiderAppController extends APIController
|
||||||
{
|
{
|
||||||
$required_params = ['jo_id'];
|
$required_params = ['jo_id'];
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
||||||
if (!empty($msg))
|
if (!empty($msg))
|
||||||
|
|
@ -453,17 +452,15 @@ class RiderAppController extends APIController
|
||||||
{
|
{
|
||||||
$required_params = ['jo_id'];
|
$required_params = ['jo_id'];
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
||||||
if (!empty($msg))
|
if (!empty($msg))
|
||||||
|
|
@ -510,17 +507,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
// get rider's current job order
|
// get rider's current job order
|
||||||
$jo = $rider->getCurrentJobOrder();
|
$jo = $rider->getCurrentJobOrder();
|
||||||
|
|
@ -552,17 +547,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
// get rider's current job order
|
// get rider's current job order
|
||||||
$jo = $rider->getCurrentJobOrder();
|
$jo = $rider->getCurrentJobOrder();
|
||||||
|
|
@ -594,17 +587,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
// get rider's current job order
|
// get rider's current job order
|
||||||
$jo = $rider->getCurrentJobOrder();
|
$jo = $rider->getCurrentJobOrder();
|
||||||
|
|
@ -636,17 +627,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
// get rider's current job order
|
// get rider's current job order
|
||||||
$jo = $rider->getCurrentJobOrder();
|
$jo = $rider->getCurrentJobOrder();
|
||||||
|
|
@ -673,17 +662,15 @@ class RiderAppController extends APIController
|
||||||
{
|
{
|
||||||
$required_params = ['jo_id'];
|
$required_params = ['jo_id'];
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
||||||
if (!empty($msg))
|
if (!empty($msg))
|
||||||
|
|
@ -735,17 +722,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
// get rider's current job order
|
// get rider's current job order
|
||||||
$jo = $rider->getCurrentJobOrder();
|
$jo = $rider->getCurrentJobOrder();
|
||||||
|
|
@ -778,17 +763,15 @@ class RiderAppController extends APIController
|
||||||
{
|
{
|
||||||
$required_params = ['jo_id'];
|
$required_params = ['jo_id'];
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
||||||
if (!empty($msg))
|
if (!empty($msg))
|
||||||
|
|
@ -879,8 +862,8 @@ class RiderAppController extends APIController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for riders, use rider session id
|
// for riders, use rider id
|
||||||
$user_id = $rapi_session->getID();
|
$user_id = $rider->getID();
|
||||||
$source = WarrantySource::RAPI;
|
$source = WarrantySource::RAPI;
|
||||||
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source, $jo->getCustomer(), $jo->getCustomerVehicle()->getVehicle());
|
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source, $jo->getCustomer(), $jo->getCustomerVehicle()->getVehicle());
|
||||||
}
|
}
|
||||||
|
|
@ -913,17 +896,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
// get rider's current job order
|
// get rider's current job order
|
||||||
$jo = $rider->getCurrentJobOrder();
|
$jo = $rider->getCurrentJobOrder();
|
||||||
|
|
@ -956,17 +937,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
// get rider's current job order
|
// get rider's current job order
|
||||||
$jo = $rider->getCurrentJobOrder();
|
$jo = $rider->getCurrentJobOrder();
|
||||||
|
|
@ -998,17 +977,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
$rider->setAvailable(true);
|
$rider->setAvailable(true);
|
||||||
|
|
||||||
|
|
@ -1028,15 +1005,15 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$promos = $em->getRepository(Promo::class)->findAll();
|
$promos = $em->getRepository(Promo::class)->findAll();
|
||||||
|
|
||||||
|
|
@ -1066,16 +1043,16 @@ class RiderAppController extends APIController
|
||||||
$params = implode(', ', $missing);
|
$params = implode(', ', $missing);
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
return new APIResponse(false, 'Missing parameter(s): ' . $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get capi user
|
||||||
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get rider id from capi user metadata
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// check if capi user already has a rider api user
|
return new APIResponse(false, 'No rider found.');
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
|
||||||
|
|
||||||
// are we logged in?
|
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$batts = $em->getRepository(Battery::class)->findAll();
|
$batts = $em->getRepository(Battery::class)->findAll();
|
||||||
$models = $em->getRepository(BatteryModel::class)->findAll();
|
$models = $em->getRepository(BatteryModel::class)->findAll();
|
||||||
|
|
@ -1126,17 +1103,15 @@ class RiderAppController extends APIController
|
||||||
// allow rider to change service, promo, battery and trade-in options
|
// allow rider to change service, promo, battery and trade-in options
|
||||||
$required_params = ['jo_id', 'stype_id', 'promo_id'];
|
$required_params = ['jo_id', 'stype_id', 'promo_id'];
|
||||||
|
|
||||||
// get capi user to link to rider api user
|
// get capi user
|
||||||
$capi_user_id = $this->getUser()->getID();
|
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
||||||
|
if ($capi_user == null)
|
||||||
|
return new APIResponse(false, 'User not found.');
|
||||||
|
|
||||||
// check if capi user already has a rider api user
|
// get rider id from capi user metadata
|
||||||
$rapi_session = $em->getRepository(RiderAPISession::class)->findOneBy(['capi_user_id' => $capi_user_id]);
|
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||||
|
if ($rider == null)
|
||||||
// are we logged in?
|
return new APIResponse(false, 'No rider found.');
|
||||||
if (!$rapi_session->hasRider())
|
|
||||||
return new APIResponse(false, 'No logged in rider.');
|
|
||||||
|
|
||||||
$rider = $rapi_session->getRider();
|
|
||||||
|
|
||||||
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
$msg = $this->checkJO($req, $required_params, $jo, $rider);
|
||||||
if (!empty($msg))
|
if (!empty($msg))
|
||||||
|
|
@ -1262,6 +1237,26 @@ class RiderAppController extends APIController
|
||||||
return new APIResponse(true, 'Job order service changed.', $data);
|
return new APIResponse(true, 'Job order service changed.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getCAPIUser($id, EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$capi_user = $em->getRepository(APIUser::class)->find($id);
|
||||||
|
return $capi_user;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRiderFromCAPI($capi_user, $em)
|
||||||
|
{
|
||||||
|
// TODO: uncomment once getMetadata is available
|
||||||
|
/*
|
||||||
|
$metadata = $capi_user->getMetadata();
|
||||||
|
//get rider id from metadata
|
||||||
|
$rider_id = $metadata['rider_id'];
|
||||||
|
// get rider
|
||||||
|
$rider = $em->getRepository(Rider::class)->find($rider_id);
|
||||||
|
return $rider;
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected function checkMissingParameters(Request $req, $params = [])
|
protected function checkMissingParameters(Request $req, $params = [])
|
||||||
{
|
{
|
||||||
$missing = [];
|
$missing = [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue