diff --git a/controllers/GenericEntityApiController.php b/controllers/GenericEntityApiController.php index 3a2f1754..de0775ac 100644 --- a/controllers/GenericEntityApiController.php +++ b/controllers/GenericEntityApiController.php @@ -50,6 +50,10 @@ class GenericEntityApiController extends BaseApiController } $object = $this->getDatabase()->{$args['entity']}($args['objectId']); + if ($object == null) { + return $this->GenericErrorResponse($response, 'Object not found', 404); + } + $object['userfields'] = $userfields; return $this->ApiResponse($response, $object); diff --git a/grocy.openapi.json b/grocy.openapi.json index 20af6b9f..b8d587b1 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -395,6 +395,16 @@ } } } + }, + "404": { + "description": "Object not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GenericErrorResponse" + } + } + } } } }, diff --git a/migrations/0108.sql b/migrations/0108.sql new file mode 100644 index 00000000..c0956ed4 --- /dev/null +++ b/migrations/0108.sql @@ -0,0 +1,27 @@ +DELETE FROM shopping_list +WHERE shopping_list_id NOT IN (SELECT id FROM shopping_lists); + +CREATE TRIGGER remove_items_from_deleted_shopping_list AFTER DELETE ON shopping_lists +BEGIN + DELETE FROM shopping_list WHERE shopping_list_id = OLD.id; +END; + +CREATE TRIGGER prevent_infinite_nested_recipes_INS BEFORE INSERT ON recipes_nestings +BEGIN + SELECT CASE WHEN(( + SELECT 1 + FROM recipes_nestings_resolved rnr + WHERE NEW.recipe_id = rnr.includes_recipe_id + AND NEW.includes_recipe_id = rnr.recipe_id + ) NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END; +END; + +CREATE TRIGGER prevent_infinite_nested_recipes_UPD BEFORE UPDATE ON recipes_nestings +BEGIN + SELECT CASE WHEN(( + SELECT 1 + FROM recipes_nestings_resolved rnr + WHERE NEW.recipe_id = rnr.includes_recipe_id + AND NEW.includes_recipe_id = rnr.recipe_id + ) NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END; +END; diff --git a/services/StockService.php b/services/StockService.php index ae499507..8350b6db 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -95,7 +95,7 @@ class StockService extends BaseService if ($excludeExpired) { - $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime('now')), '>'); + $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime('-1 days')), '>'); } return $currentStock;