mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +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}": {
|
"/stock/products/by-barcode/{barcode}": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Returns details of the product from its barcode",
|
"summary": "Returns details of the given product by its barcode",
|
||||||
"tags": [
|
"tags": [
|
||||||
"Stock"
|
"Stock"
|
||||||
],
|
],
|
||||||
|
@ -40,20 +40,14 @@ class StockService extends BaseService
|
|||||||
|
|
||||||
public function GetProductIdFromBarcode(string $barcode)
|
public function GetProductIdFromBarcode(string $barcode)
|
||||||
{
|
{
|
||||||
$sql = "SELECT id FROM products WHERE (',' || barcode || ',') LIKE '%,' || :barcode || ',%'";
|
$potentialProduct = $this->Database->products()->where('barcode LIKE :1', '%' . $barcode . '%')->limit(1)->fetch();
|
||||||
$query = $this->DatabaseService->ExecuteDbQuery($sql);
|
|
||||||
|
|
||||||
$query->bindParam("barcode", $barcode);
|
if ($potentialProduct === null)
|
||||||
|
|
||||||
$query->execute();
|
|
||||||
|
|
||||||
$productId = $query->fetchColumn(0);
|
|
||||||
|
|
||||||
if ($productId == 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)
|
public function GetExpiringProducts(int $days = 5, bool $excludeExpired = false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user