diff --git a/src/Controller/ResqAPI/BatteryController.php b/src/Controller/ResqAPI/BatteryController.php new file mode 100644 index 00000000..3f44294d --- /dev/null +++ b/src/Controller/ResqAPI/BatteryController.php @@ -0,0 +1,168 @@ +acl_gen = $acl_gen; + } + + public function getCompatibleBatteries(Request $req, $vid, EntityManagerInterface $em) + { + // check required parameters and api key + $required_params = []; + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // get vehicle + $vehicle = $em->getRepository(Vehicle::class)->find($vid); + if ($vehicle == null) + { + $res->setError(true) + ->setErrorMessage('Invalid vehicle'); + return $res->getReturnResponse(); + } + + // batteries + $batt_list = []; + $batts = $vehicle->getBatteries(); + foreach ($batts as $batt) + { + // TODO: Add warranty_tnv to battery information + $batt_list[] = [ + 'id' => $batt->getID(), + 'mfg_id' => $batt->getManufacturer()->getID(), + 'mfg_name' => $batt->getManufacturer()->getName(), + 'model_id' => $batt->getModel()->getID(), + 'model_name' => $batt->getModel()->getName(), + 'size_id' => $batt->getSize()->getID(), + 'size_name' => $batt->getSize()->getName(), + 'price' => $batt->getSellingPrice(), + 'wty_private' => $batt->getWarrantyPrivate(), + 'wty_commercial' => $batt->getWarrantyCommercial(), + 'image_url' => $this->getBatteryImageURL($req, $batt), + ]; + } + + // data + $data = [ + 'vehicle' => [ + 'id' => $vehicle->getID(), + 'mfg_id' => $vehicle->getManufacturer()->getID(), + 'mfg_name' => $vehicle->getManufacturer()->getName(), + 'make' => $vehicle->getMake(), + 'model_year_from' => $vehicle->getModelYearFrom(), + 'model_year_to' => $vehicle->getModelYearTo(), + ], + 'batteries' => $batt_list, + ]; + $res->setData($data); + + return $res->getReturnResponse(); + } + + // 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: 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: 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; + } +} diff --git a/src/Controller/ResqAPI/PartnerController.php b/src/Controller/ResqAPI/PartnerController.php new file mode 100644 index 00000000..e6bc0157 --- /dev/null +++ b/src/Controller/ResqAPI/PartnerController.php @@ -0,0 +1,257 @@ +acl_gen = $acl_gen; + } + + public function getClosestPartners(Request $req, EntityManagerInterface $em) + { + $required_params = [ + 'longitude', + 'latitude', + 'service_id', + 'limit', + ]; + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + $long = $req->query->get('longitude'); + $lat = $req->query->get('latitude'); + $service_id = $req->query->get('service_id'); + $limit = $req->query->get('limit'); + + // get partners within range + $query = $em->createQuery('SELECT p, st_distance(p.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Partner p + JOIN App\Entity\Service s where s.id = :service_id ORDER BY dist') + ->setParameter('lat', $lat) + ->setParameter('lng', $long) + ->setParameter('service_id', $service_id); + + $query->setMaxResults($limit); + $result = $query->getResult(); + + $data = []; + $partners = []; + foreach($result as $row) + { + $partners[] = [ + 'id' => $row[0]->getID(), + 'name' => $row[0]->getName(), + 'branch' => $row[0]->getBranch(), + 'address' => $row[0]->getAddress(), + 'contact_nums' => $row[0]->getContactNumbers(), + 'time_open' => $row[0]->getTimeOpen()->format("g:i A"), + 'time_close' => $row[0]->getTimeClose()->format("g:i A"), + 'longitude' => $row[0]->getCoordinates()->getLongitude(), + 'latitude' => $row[0]->getCoordinates()->getLatitude(), + 'db_distance' => $row['dist'], + ]; + } + + $data['partners'] = $partners; + + $res->setData($data); + + return $res->getReturnResponse(); + } + + public function getPartnerInformation(Request $req, $pid, EntityManagerInterface $em) + { + $required_params = []; + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // get partner + $partner = $em->getRepository(Partner::class)->findOneBy(['id' => $pid]); + if ($partner == null) + { + $res->setError(true) + ->setErrorMessage('No partner found.'); + return $res->getReturnResponse(); + } + + // get reviews for partner + $reviews = $em->getRepository(Review::class)->findBy(['partner' => $partner]); + + // get average rating for all reviews + $average_rating = 0; + if (!empty($reviews)) + { + $rating = 0; + foreach($reviews as $review) + { + $rating = $rating + $review->getRating(); + } + + $average_rating = $rating / sizeof($reviews); + } + + $data['partner'] = [ + 'id' => $partner->getID(), + 'name' => $partner->getName(), + 'branch' => $partner->getBranch(), + 'address' => $partner->getAddress(), + 'contact_nums' => $partner->getContactNumbers(), + 'time_open' => $partner->getTimeOpen()->format("g:i A"), + 'time_close' => $partner->getTimeClose()->format("g:i A"), + 'longitude' => $partner->getCoordinates()->getLongitude(), + 'latitude' => $partner->getCoordinates()->getLatitude(), + 'average_rating' => $average_rating, + ]; + + $res->setData($data); + + return $res->getReturnResponse(); + } + + public function reviewPartner($pid, Request $req, EntityManagerInterface $em) + { + $required_params = [ + 'rating', + 'message', + ]; + + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + $rating = $req->request->get('rating'); + $msg = $req->request->get('message'); + + // TODO: check rating if 1 - 5 + + // check if partner exists + $partner = $em->getRepository(Partner::class)->find($pid); + if ($partner == null) + { + $res->setError(true) + ->setErrorMessage('No partner found.'); + return $res->getReturnResponse(); + } + + $rev = new Review(); + $rev->setRating($rating) + ->setMessage($msg) + ->setPartner($partner) + ->setMobileSession($this->session); + + // save to db + $em->persist($rev); + $em->flush(); + + $data = []; + $res->setData($data); + + return $res->getReturnResponse(); + } + + // 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: 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: 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; + } +} diff --git a/src/Controller/ResqAPI/PromoController.php b/src/Controller/ResqAPI/PromoController.php new file mode 100644 index 00000000..75dc419c --- /dev/null +++ b/src/Controller/ResqAPI/PromoController.php @@ -0,0 +1,124 @@ +acl_gen = $acl_gen; + } + + public function listPromos(Request $req, EntityManagerInterface $em) + { + // check required parameters and api key + $required_params = []; + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + return $res->getReturnResponse(); + } + + // 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: 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: 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; + } +} diff --git a/src/Controller/ResqAPI/RiderController.php b/src/Controller/ResqAPI/RiderController.php new file mode 100644 index 00000000..b7f97783 --- /dev/null +++ b/src/Controller/ResqAPI/RiderController.php @@ -0,0 +1,368 @@ +acl_gen = $acl_gen; + } + + // TODO: needs to be modified for mobile user + public function getRiderStatus(Request $req, RiderTracker $rt, EntityManagerInterface $em) + { + $required_params = []; + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // get customer + $cust = $this->session->getCustomer(); + if ($cust == null) + { + $res->setError(true) + ->setErrorMessage('No customer information found'); + return $res->getReturnResponse(); + } + + $ongoing_jos = $this->getOngoingJobOrders($cust, $em); + + if (count($ongoing_jos) <= 0) + { + try + { + // check if the latest fulfilled jo they have needs rider rating + $query = $em->createQuery('select jo from App\Entity\JobOrder jo where jo.customer = :cust and jo.status = :status order by jo.date_fulfill desc'); + $fulfill_jo = $query->setParameters([ + 'cust' => $cust, + 'status' => JOStatus::FULFILLED, + ]) + ->setMaxResults(1) + ->getSingleResult(); + } + catch (Exception $e) + { + // no pending + $res->setData([ + 'status' => APIRiderStatus::NO_PENDING_JO + ]); + return $res->getReturnResponse(); + } + + // we got a recently fulfilled job order + if ($fulfill_jo) + { + // check if the rider has been rated + if (!$fulfill_jo->hasRiderRating()) + { + $dest = $fulfill_jo->getCoordinates(); + + $data = [ + 'jo_id' => $fulfill_jo->getID(), + 'service_type' => $fulfill_jo->getServiceType(), + 'destination' => [ + 'long' => $dest->getLongitude(), + 'lat' => $dest->getLatitude(), + ], + 'delivery_address' => $fulfill_jo->getDeliveryAddress(), + 'delivery_instructions' => $fulfill_jo->getDeliveryInstructions(), + ]; + + $rider = $fulfill_jo->getRider(); + + // default image url + $url_prefix = $req->getSchemeAndHttpHost(); + $image_url = $url_prefix . '/assets/images/user.gif'; + if ($rider->getImageFile() != null) + $image_url = $url_prefix . '/uploads/' . $rider->getImageFile(); + + $data['status'] = APIRiderStatus::RIDER_RATING; + // default rider location to hub + $data['rider'] = [ + 'id' => $rider->getID(), + 'name' => $rider->getFullName(), + 'plate_num' => $rider->getPlateNumber(), + 'contact_num' => $rider->getContactNumber(), + 'image_url' => $image_url, + ]; + $res->setData($data); + return $res->getReturnResponse(); + } + } + + // no pending + $res->setData([ + 'status' => APIRiderStatus::NO_PENDING_JO + ]); + return $res->getReturnResponse(); + } + + // get first jo that's pending + $jo = $ongoing_jos[0]; + $dest = $jo->getCoordinates(); + + $data = [ + 'jo_id' => $jo->getID(), + 'service_type' => $jo->getServiceType(), + 'destination' => [ + 'long' => $dest->getLongitude(), + 'lat' => $dest->getLatitude(), + ], + 'delivery_address' => $jo->getDeliveryAddress(), + 'delivery_instructions' => $jo->getDeliveryInstructions(), + ]; + + switch ($jo->getStatus()) + { + case JOStatus::PENDING: + $data['status'] = APIRiderStatus::OUTLET_ASSIGN; + $res->setData($data); + return $res->getReturnResponse(); + case JOStatus::RIDER_ASSIGN: + $data['status'] = APIRiderStatus::RIDER_ASSIGN; + $res->setData($data); + return $res->getReturnResponse(); + case JOStatus::ASSIGNED: + case JOStatus::IN_TRANSIT: + case JOStatus::IN_PROGRESS: + $rider = $jo->getRider(); + // get rider coordinates from redis + $coord = $rt->getRiderLocation($rider->getID()); + + // default image url + $url_prefix = $req->getSchemeAndHttpHost(); + $image_url = $url_prefix . '/assets/images/user.gif'; + if ($rider->getImageFile() != null) + $image_url = $url_prefix . '/uploads/' . $rider->getImageFile(); + + $data['status'] = APIRiderStatus::RIDER_PICK_UP; + // TODO: fix this to actual location of rider + // default rider location to hub + $data['rider'] = [ + 'id' => $rider->getID(), + 'name' => $rider->getFullName(), + 'plate_num' => $rider->getPlateNumber(), + 'contact_num' => $rider->getContactNumber(), + 'image_url' => $image_url, + 'location' => [ + 'long' => $coord->getLongitude(), + 'lat' => $coord->getLatitude() + ] + ]; + $res->setData($data); + return $res->getReturnResponse(); + } + + $res->setData($data); + + return $res->getReturnResponse(); + } + + // TODO: needs to be modified for mobile user + public function addRiderRating(Request $req, EntityManagerInterface $em) + { + $required_params = [ + 'jo_id', + 'rating', + ]; + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // get customer + $cust = $this->session->getCustomer(); + if ($cust == null) + { + $res->setError(true) + ->setErrorMessage('No customer information found'); + 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 rider + $rider = $jo->getRider(); + if ($rider == null) + { + $res->setError(true) + ->setErrorMessage('No rider 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 complete + + // add rider rating + $rating_num = $req->request->get('rating', -1); + + // if rating is -1 + if ($rating_num == -1) + { + $jo->setHasRiderRating(); + $em->flush(); + + $res->setData([]); + + return $res->getReturnResponse(); + } + + + $rating = new RiderRating(); + $rating->setRider($rider) + ->setCustomer($cust) + ->setJobOrder($jo) + ->setRating($rating_num); + + // rider rating comment + $comment = $req->request->get('comment'); + if (!empty($comment)) + $rating->setComment($comment); + + // mark jo as rider rated already + $jo->setHasRiderRating(); + + $em->persist($rating); + $em->flush(); + + // TODO: set average rating in rider entity + + $res->setData([]); + + return $res->getReturnResponse(); + } + + protected function getOngoingJobOrders($cust, $em) + { + $ongoing_jos = $em->getRepository(JobOrder::class)->findBy([ + 'customer' => $cust, + 'status' => [JOStatus::PENDING, JOStatus::RIDER_ASSIGN, JOStatus::IN_TRANSIT, JOStatus::ASSIGNED, JOStatus::IN_PROGRESS], + ]); + + return $ongoing_jos; + } + + // 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: 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: 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; + } +} diff --git a/src/Controller/ResqAPI/ServiceController.php b/src/Controller/ResqAPI/ServiceController.php new file mode 100644 index 00000000..0c47867e --- /dev/null +++ b/src/Controller/ResqAPI/ServiceController.php @@ -0,0 +1,164 @@ +acl_gen = $acl_gen; + } + + public function listServices(Request $req, EntityManagerInterface $em) + { + $required_params = []; + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // services + $results = $em->getRepository(Service::class)->findAll(); + if (empty($results)) + { + $res->setError(true) + ->setErrorMessage('No services available.'); + return $res->getReturnResponse(); + } + + $services = []; + foreach ($results as $result) + { + /* + // get partners + $partners = []; + $service_partners = $result->getPartners(); + foreach($service_partners as $sp) + { + $partners[] = [ + 'id' => $sp->getID(), + 'name' => $sp->getName(), + 'branch' => $sp->getBranch(), + 'address' => $sp->getAddress(), + 'contact_nums' => $sp->getContactNumbers(), + 'time_open' => $sp->getTimeOpen()->format("g:i A"), + 'time_close' => $sp->getTimeClose()->format("g:i A"), + ]; + } + */ + + $services[] = [ + 'id' => $result->getID(), + 'name' => $result->getName(), + // 'partners' => $partners, + ]; + } + + $data['services'] = $services; + + $res->setData($data); + + return $res->getReturnResponse(); + } + + // 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: 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: 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; + } +}