diff --git a/backend/src/recipes/recipes.service.ts b/backend/src/recipes/recipes.service.ts index 299ce0a7..efe4d915 100644 --- a/backend/src/recipes/recipes.service.ts +++ b/backend/src/recipes/recipes.service.ts @@ -303,7 +303,16 @@ export class RecipesService { } async update(id: number, updateRecipeDto: CreateRecipeDto) { - // Först, ta bort gamla ingredienser + // Verifiera att receptet finns + const existingRecipe = await this.prisma.recipe.findUnique({ + where: { id }, + }); + + if (!existingRecipe) { + throw new NotFoundException(`Recipe with id ${id} not found`); + } + + // Ta bort gamla ingredienser await this.prisma.recipeIngredient.deleteMany({ where: { recipeId: id }, }); @@ -318,7 +327,7 @@ export class RecipesService { ingredients: { create: updateRecipeDto.ingredients.map((ingredient) => ({ productId: ingredient.productId, - quantity: ingredient.quantity.toString(), + quantity: ingredient.quantity, unit: ingredient.unit, note: ingredient.note || null, })), @@ -345,7 +354,7 @@ export class RecipesService { ingredients: { create: createRecipeDto.ingredients.map((ingredient) => ({ productId: ingredient.productId, - quantity: ingredient.quantity.toString(), + quantity: ingredient.quantity, unit: ingredient.unit, note: ingredient.note || null, })),