Just some changes for the new product-by-barcode API method (references #171)

This commit is contained in:
Bernd Bestel 2019-03-10 13:43:58 +01:00
parent 91289588b5
commit 75241fc61f
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 6 additions and 12 deletions

View File

@ -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"
],

View File

@ -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)