Add index for capi user ID. Add checking if user already registered. #591

This commit is contained in:
Korina Cordero 2021-07-01 08:26:36 +00:00
parent 8fd9aed174
commit edaa514f57
2 changed files with 19 additions and 4 deletions

View file

@ -44,6 +44,12 @@ class CustomerController extends APIController
// get capi user to link to mobile user
$user_id = $this->getUser()->getID();
// check if capi user already has a mobile user
$mobile_user = $this->findMobileUser($user_id, $em);
if ($mobile_user != null)
return new APIResponse(false, 'User already registered');
// retry until we get a unique id
while (true)
{
@ -82,9 +88,8 @@ class CustomerController extends APIController
}
// return data
// need to make sure the names returned to app are the same
// so we still use session_id name
// TODO: depending on what data type we return, this might need changes
// TODO: do we need to return the same names as before?
// right now, still usind the old names so we use session_id name
$data = [
'session_id' => $mobile_user->getID()
];
@ -468,6 +473,13 @@ class CustomerController extends APIController
return $res->getReturnResponse();
}
protected function findMobileUser($user_id, $em)
{
$mobile_user = $em->getRepository(MobileUser::class)->findBy(['capi_user_id' => $user_id]);
return $mobile_user;
}
// TODO: this might not be needed if we use APIController's checkRequiredParameters
// or we put this into a service?
protected function checkMissingParameters(Request $req, $params = [])

View file

@ -10,7 +10,10 @@ use DateTime;
/**
* @ORM\Entity
* @ORM\Table(name="mobile_user")
* @ORM\Table(
* name="mobile_user",
* indexes={@ORM\Index(name="capi_user_idx", columns={"capi_user_id"})}
* )
*/
class MobileUser
{