From 3e38cb5f9892508d01567a7bc5c9ddb30884a361 Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Thu, 9 Apr 2026 22:23:13 +0200 Subject: [PATCH] Add create method to RecipesService for recipe creation with ingredients --- backend/src/recipes/recipes.service.ts | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/backend/src/recipes/recipes.service.ts b/backend/src/recipes/recipes.service.ts index 8ee2a305..fd9efb48 100644 --- a/backend/src/recipes/recipes.service.ts +++ b/backend/src/recipes/recipes.service.ts @@ -301,4 +301,31 @@ export class RecipesService { return recipe; } + + async create(createRecipeDto: CreateRecipeDto) { + const recipe = await this.prisma.recipe.create({ + data: { + name: createRecipeDto.name, + description: createRecipeDto.description || null, + instructions: createRecipeDto.instructions || null, + ingredients: { + create: createRecipeDto.ingredients.map((ingredient) => ({ + productId: ingredient.productId, + quantity: ingredient.quantity.toString(), + unit: ingredient.unit, + note: ingredient.note || null, + })), + }, + }, + include: { + ingredients: { + include: { + product: true, + }, + }, + }, + }); + + return recipe; + } } \ No newline at end of file