Add create method to RecipesService for recipe creation with ingredients
This commit is contained in:
@@ -301,4 +301,31 @@ export class RecipesService {
|
|||||||
|
|
||||||
return recipe;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user