Add create method to RecipesService for recipe creation with ingredients

This commit is contained in:
Nils-Johan Gynther
2026-04-09 22:23:13 +02:00
parent bc89e3038b
commit 3e38cb5f98
+27
View File
@@ -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;
}
}