diff --git a/services/nginx/app/routes/vehiclesRoute.php b/services/nginx/app/routes/vehiclesRoute.php index 94084d96..43140327 100644 --- a/services/nginx/app/routes/vehiclesRoute.php +++ b/services/nginx/app/routes/vehiclesRoute.php @@ -734,13 +734,29 @@ class vehiclesRoute $search = (string)self::getParameter('search'); self::requireMinLength('search', 1); self::requireMaxLength('search', 12); + $department = null; + // If department is set, validate it + if (self::isParametersSet(['department'])) { + $department = (int)self::getParameter('department'); + self::requireType($department, self::type_int()); + self::requireMinValue($department, 1); + self::requireMaxValue($department, 999999); + // Check if the department exists + $department_o = new departments_o(); + $department_o->select($department); + if (!$department_o->exists()) { + $response->error('Department not found', 404); + } + self::requireDepartmentAccess($department); + } // Strip the search term of whitespace $search = preg_replace('/\s+/', '', $search); /** Get the different lists of registration numbers */ $options = ['limit' => 10]; + $booked_filters = [...($department ? ['department' => $department] : [])]; $verified_regs = self::getVerifiedRegs($search, $options); $known_regs = self::getKnownRegs($search, $options); - $booked_regs = self::getBookedRegs($search, $options); + $booked_regs = self::getBookedRegs($search, $options, $booked_filters); $unknown_regs = array_filter(array_unique(array_merge([...self::getUnknownRegs($search, $options), $search]))); // Add the search term as the first item, to ensure it is included in the results /** * Prevent overlaps between the lists @@ -930,7 +946,7 @@ class vehiclesRoute }, $results); } - private static function getBookedRegs(string $search, array $options = ['limit' => null]): array + private static function getBookedRegs(string $search, array $options = ['limit' => null], ?array $filters = []): array { $bookings_o = new order_bookings_o(); /** @@ -957,6 +973,7 @@ class vehiclesRoute [ 'reg_1' => $search, 'order_id' => null, + ...$filters ], ['reg_1'], $options @@ -965,6 +982,7 @@ class vehiclesRoute [ 'reg_2' => $search, 'order_id' => null, + ...$filters ], ['reg_2'], $options