From c83a7a1ae57f9c9f1cdc2995b0338ac99f0f4325 Mon Sep 17 00:00:00 2001 From: Sveneld Date: Sun, 2 Jun 2024 13:50:11 +0200 Subject: [PATCH] check count of rented biked for qr system --- src/Rent/AbstractRentSystem.php | 2 +- src/Rent/RentSystemQR.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Rent/AbstractRentSystem.php b/src/Rent/AbstractRentSystem.php index 971bc1b..79a1df0 100644 --- a/src/Rent/AbstractRentSystem.php +++ b/src/Rent/AbstractRentSystem.php @@ -14,7 +14,7 @@ */ abstract class AbstractRentSystem implements RentSystemInterface { - private const ERROR = 1; + protected const ERROR = 1; /** * @var DbInterface */ diff --git a/src/Rent/RentSystemQR.php b/src/Rent/RentSystemQR.php index da195e8..3e59873 100644 --- a/src/Rent/RentSystemQR.php +++ b/src/Rent/RentSystemQR.php @@ -18,14 +18,15 @@ public function returnBike($userId, $bikeId, $standName, $note = '', $force = fa if ($bikeId !== 0) { $this->logger->error("Bike number could not be provided via QR code", ["userId" => $userId]); - return $this->response(_('Invalid bike number'), ERROR); + return $this->response(_('Invalid bike number'), self::ERROR); } $result = $this->db->query("SELECT bikeNum FROM bikes WHERE currentUser=$userId ORDER BY bikeNum"); $bikeNumber = $result->rowCount(); - $bikeId = $result->fetchAssoc()['bikeNum']; - if ($bikeNumber > 1) { + if ($bikeNumber === 0) { + return $this->response(_('You currently have no rented bikes.'), self::ERROR); + } elseif ($bikeNumber > 1) { $message = _('You have') . ' ' . $bikeNumber . ' ' . _('rented bikes currently. QR code return can be used only when 1 bike is rented. Please, use web'); if ($this->connectorsConfig["sms"]) { @@ -33,8 +34,9 @@ public function returnBike($userId, $bikeId, $standName, $note = '', $force = fa } $message .= _(' to return the bikes.'); - return $this->response($message, ERROR); + return $this->response($message, self::ERROR); } + $bikeId = $result->fetchAssoc()['bikeNum']; return parent::returnBike($userId, $bikeId, $standName, $note, $force); }