diff --git a/src/Controller/ResqAPI/CustomerController.php b/src/Controller/ResqAPI/CustomerController.php index 287fd082..595da8a3 100644 --- a/src/Controller/ResqAPI/CustomerController.php +++ b/src/Controller/ResqAPI/CustomerController.php @@ -98,9 +98,12 @@ class CustomerController extends APIController // return data // TODO: do we need to return the same names as before? - // right now, still usind the old names so we use session_id name + // right now, still using the old names so we use session_id name $data = [ - 'session_id' => $mobile_user->getID() + 'session_id' => $mobile_user->getID(), + 'phone_model' => $mobile_user->getPhoneModel(), + 'os_version' => $mobile_user->getOSVersion(), + 'phone_id' => $mobile_user->getPhoneID(), ]; // response @@ -225,6 +228,8 @@ class CustomerController extends APIController } // TODO: check if mobile matches mobile of customer + // need to "clean" the mobile number. Mobile user stores the number with the area code prepended + // Customer stores the number without the area code $customer = $this->findCustomerByNumber($mobile_user->getPhoneNumber(), $em); if ($customer != null) { @@ -319,6 +324,11 @@ class CustomerController extends APIController $em->flush(); + $data = [ + 'first_name' => $cust->getFirstName(), + 'last_name' => $cust->getLastName(), + ]; + return new APIResponse(true, 'Customer info updated'); } @@ -452,8 +462,12 @@ class CustomerController extends APIController $em->flush(); + $data = [ + 'device_id' => $mobile_user->getDevicePushID(), + ]; + // response - return new APIResponse(true, 'Device ID updated'); + return new APIResponse(true, 'Device ID updated', $data); } public function privacySettings(Request $req, EntityManagerInterface $em, MobileAPIHandler $mah) @@ -555,6 +569,7 @@ class CustomerController extends APIController foreach($customers as $customer) { + error_log('no customer?'); $vehicles = $customer->getVehicles(); if (count($vehicles) > $car_count) { @@ -600,89 +615,4 @@ class CustomerController extends APIController $message = "Your Resq confirmation code is $code."; $rt->sendSMS($phone_number, 'MOTOLITE', $message); } - - - // 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 = []) - { - $missing = []; - - // check if parameters are there - foreach ($params as $param) - { - if ($req->getMethod() == 'GET') - { - $check = $req->query->get($param); - if (empty($check)) - $missing[] = $param; - } - else if ($req->getMethod() == 'POST') - { - $check = $req->request->get($param); - if (empty($check)) - $missing[] = $param; - } - else - return $params; - } - - return $missing; - } - - // TODO: since we broke the functions into separate files, we need - // to figure out how to make this accessible to all ResqAPI controllers - protected function checkParamsAndKey(Request $req, $em, $params) - { - // TODO: depends on what we decide to return - // returns APIResult object - $res = new APIResult(); - - // check for api_key in query string - $api_key = $req->query->get('api_key'); - if (empty($api_key)) - { - $res->setError(true) - ->setErrorMessage('Missing API key'); - return $res; - } - - // check missing parameters - $missing = $this->checkMissingParameters($req, $params); - if (count($missing) > 0) - { - $miss_string = implode(', ', $missing); - $res->setError(true) - ->setErrorMessage('Missing parameter(s): ' . $miss_string); - return $res; - } - - // check api key - $mobile_user = $this->checkAPIKey($em, $req->query->get('api_key')); - if ($mobile_user == null) - { - $res->setError(true) - ->setErrorMessage('Invalid API Key'); - return $res; - } - - // store session - $this->session = $sess; - - return $res; - } - - // TODO: type hint entity manager - // TODO: since we broke the functions into separate files, we need - // to figure out how to make this accessible to all ResqAPI controllers - protected function checkAPIKey($em, $api_key) - { - // find the api key (session id) - // TODO: user validation needs to be changed - $m_user = $em->getRepository(MobileUser::class)->find($api_key); - if ($m_user == null) - return null; - - return $m_user; - } }