From 95a070051e53bd5adf8a848e3ea02eb0a06cb12d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 20 Jul 2020 08:21:34 +0000 Subject: [PATCH] Add checking for assigned job orders when rider is logging out or going offline. #437 --- .../RiderAPIHandler/CMBRiderAPIHandler.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index fc2b1272..72bc1c78 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -251,6 +251,17 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface // make rider unavailable $rider = $this->session->getRider(); + // check if rider has assigned JOs + $assigned_jos = $this->em->getRepository(JobOrder::class)->findBy(['rider' => $rider->getID(), 'status' => JOStatus::ASSIGNED]); + if ($assigned_jos != null) + { + $data = [ + 'title' => 'Failed Logout', + 'error' => 'Rider has assigned job orders.' + ]; + return $data; + } + $rider->setAvailable(false); $rider->setActive(false); @@ -314,6 +325,17 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface // set rider to unavailable to take on JOs $rider = $this->session->getRider(); + // check if rider has assigned JOs + $assigned_jos = $this->em->getRepository(JobOrder::class)->findBy(['rider' => $rider->getID(), 'status' => JOStatus::ASSIGNED]); + if ($assigned_jos != null) + { + $data = [ + 'title' => 'Failed Go Offline', + 'error' => 'Rider has assigned job orders.' + ]; + return $data; + } + $rider->setAvailable(false); $this->em->flush();