delete ingredientRecipe

master
Matis MAZINGUE 10 months ago
parent d673acae09
commit 475886ab96

@ -22,8 +22,18 @@ export class RecipeService {
deleteRecipe(recipeId: number): void {
let recipes = this.getRecipes();
recipes = recipes.filter(recipe => recipe.id !== recipeId);
localStorage.setItem(this.localStorageKey, JSON.stringify(recipes));
const deletedRecipe = recipes.find(recipe => recipe.id === recipeId);
if (deletedRecipe) {
// Remove the recipe from recipes array
recipes = recipes.filter(recipe => recipe.id !== recipeId);
localStorage.setItem(this.localStorageKey, JSON.stringify(recipes));
// Remove associated IngredientRecipe objects
let ingredientRecipes = this.getIngredientRecipes(recipeId);
ingredientRecipes = ingredientRecipes.filter(ir => ir.idRecipe !== recipeId);
localStorage.setItem(this.ingredientRecipeKey, JSON.stringify(ingredientRecipes));
}
}
getIngredientRecipes(recipeId: number): IngredientRecipe[] {

Loading…
Cancel
Save