mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 02:03:35 -04:00 
			
		
		
		
	fix: send the correct value for recipe scale and ensure the body is sent correctly (#5737)
This commit is contained in:
		| @@ -1,6 +1,5 @@ | |||||||
| import { useStoreActions } from "./partials/use-actions-factory"; | import { useStoreActions } from "./partials/use-actions-factory"; | ||||||
| import { useUserApi } from "~/composables/api"; | import { useUserApi } from "~/composables/api"; | ||||||
| import { useScaledAmount } from "~/composables/recipes/use-scaled-amount"; |  | ||||||
| import type { GroupRecipeActionOut, GroupRecipeActionType } from "~/lib/api/types/household"; | import type { GroupRecipeActionOut, GroupRecipeActionType } from "~/lib/api/types/household"; | ||||||
| import type { RequestResponse } from "~/lib/api/types/non-generated"; | import type { RequestResponse } from "~/lib/api/types/non-generated"; | ||||||
| import type { Recipe } from "~/lib/api/types/recipe"; | import type { Recipe } from "~/lib/api/types/recipe"; | ||||||
| @@ -68,7 +67,7 @@ export const useGroupRecipeActions = function ( | |||||||
|         window.open(url, "_blank")?.focus(); |         window.open(url, "_blank")?.focus(); | ||||||
|         return; |         return; | ||||||
|       case "post": |       case "post": | ||||||
|         return await api.groupRecipeActions.triggerAction(action.id, recipe.slug || "", useScaledAmount(recipe.recipeServings || 1, recipeScale).scaledAmount); |         return await api.groupRecipeActions.triggerAction(action.id, recipe.slug || "", recipeScale); | ||||||
|       default: |       default: | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ export class GroupRecipeActionsAPI extends BaseCRUDAPI<CreateGroupRecipeAction, | |||||||
|   baseRoute = routes.groupRecipeActions; |   baseRoute = routes.groupRecipeActions; | ||||||
|   itemRoute = routes.groupRecipeActionsId; |   itemRoute = routes.groupRecipeActionsId; | ||||||
|  |  | ||||||
|   async triggerAction(id: string | number, recipeSlug: string, scaledAmount: number) { |   async triggerAction(id: string | number, recipeSlug: string, recipeScale: number) { | ||||||
|     return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), { scaledAmount }); |     return await this.requests.post(routes.groupRecipeActionsIdTriggerRecipeSlug(id, recipeSlug), { recipe_scale: recipeScale }); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -69,7 +69,7 @@ class GroupRecipeActionController(BaseUserController): | |||||||
|  |  | ||||||
|     @router.post("/{item_id}/trigger/{recipe_slug}", status_code=202) |     @router.post("/{item_id}/trigger/{recipe_slug}", status_code=202) | ||||||
|     def trigger_action( |     def trigger_action( | ||||||
|         self, item_id: UUID4, recipe_slug: str, bg_tasks: BackgroundTasks, scaled_amount: float = Body(1, embed=True) |         self, item_id: UUID4, recipe_slug: str, bg_tasks: BackgroundTasks, recipe_scale: float = Body(1, embed=True) | ||||||
|     ) -> None: |     ) -> None: | ||||||
|         recipe_action = self.repos.group_recipe_actions.get_one(item_id) |         recipe_action = self.repos.group_recipe_actions.get_one(item_id) | ||||||
|         if not recipe_action: |         if not recipe_action: | ||||||
| @@ -95,7 +95,7 @@ class GroupRecipeActionController(BaseUserController): | |||||||
|                 detail=ErrorResponse.respond(message="Not found."), |                 detail=ErrorResponse.respond(message="Not found."), | ||||||
|             ) from e |             ) from e | ||||||
|  |  | ||||||
|         payload = GroupRecipeActionPayload(action=recipe_action, content=recipe, scaled_amount=scaled_amount) |         payload = GroupRecipeActionPayload(action=recipe_action, content=recipe, recipe_scale=recipe_scale) | ||||||
|         bg_tasks.add_task( |         bg_tasks.add_task( | ||||||
|             task_action, |             task_action, | ||||||
|             url=recipe_action.url, |             url=recipe_action.url, | ||||||
|   | |||||||
| @@ -44,4 +44,4 @@ class GroupRecipeActionPagination(PaginationBase): | |||||||
| class GroupRecipeActionPayload(MealieModel): | class GroupRecipeActionPayload(MealieModel): | ||||||
|     action: GroupRecipeActionOut |     action: GroupRecipeActionOut | ||||||
|     content: Any |     content: Any | ||||||
|     scaled_amount: float |     recipe_scale: float | ||||||
|   | |||||||
| @@ -173,7 +173,7 @@ def test_group_recipe_actions_trigger_post( | |||||||
|     response = api_client.post( |     response = api_client.post( | ||||||
|         api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug), |         api_routes.households_recipe_actions_item_id_trigger_recipe_slug(action_id, recipe_slug), | ||||||
|         headers=unique_user.token, |         headers=unique_user.token, | ||||||
|         json={"scaled_amount": 1.0}, |         json={"recipe_scale": 1.0}, | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|     if missing_action or missing_recipe: |     if missing_action or missing_recipe: | ||||||
| @@ -190,7 +190,7 @@ def test_group_recipe_actions_trigger_invalid_type(api_client: TestClient, uniqu | |||||||
|     response = api_client.post( |     response = api_client.post( | ||||||
|         api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id), |         api_routes.households_recipe_actions_item_id_trigger_recipe_slug(recipe_action.id, recipe.id), | ||||||
|         headers=unique_user.token, |         headers=unique_user.token, | ||||||
|         json={"scaled_amount": 1.0}, |         json={"recipe_scale": 1.0}, | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|     assert response.status_code == 400 |     assert response.status_code == 400 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user