mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Just some changes for the new product-by-barcode API method (references #171)
This commit is contained in:
parent
91289588b5
commit
75241fc61f
@ -910,7 +910,7 @@
|
||||
},
|
||||
"/stock/products/by-barcode/{barcode}": {
|
||||
"get": {
|
||||
"summary": "Returns details of the product from its barcode",
|
||||
"summary": "Returns details of the given product by its barcode",
|
||||
"tags": [
|
||||
"Stock"
|
||||
],
|
||||
|
@ -40,20 +40,14 @@ class StockService extends BaseService
|
||||
|
||||
public function GetProductIdFromBarcode(string $barcode)
|
||||
{
|
||||
$sql = "SELECT id FROM products WHERE (',' || barcode || ',') LIKE '%,' || :barcode || ',%'";
|
||||
$query = $this->DatabaseService->ExecuteDbQuery($sql);
|
||||
$potentialProduct = $this->Database->products()->where('barcode LIKE :1', '%' . $barcode . '%')->limit(1)->fetch();
|
||||
|
||||
$query->bindParam("barcode", $barcode);
|
||||
|
||||
$query->execute();
|
||||
|
||||
$productId = $query->fetchColumn(0);
|
||||
|
||||
if ($productId == null)
|
||||
if ($potentialProduct === null)
|
||||
{
|
||||
throw new \Exception("Product with barcode $barcode does not exist");
|
||||
throw new \Exception("No product with barcode $barcode found");
|
||||
}
|
||||
return $productId;
|
||||
|
||||
return intval($potentialProduct->id);
|
||||
}
|
||||
|
||||
public function GetExpiringProducts(int $days = 5, bool $excludeExpired = false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user