Add update functionality for recipes and create edit page
This commit is contained in:
@@ -302,6 +302,40 @@ export class RecipesService {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
async update(id: number, updateRecipeDto: CreateRecipeDto) {
|
||||
// Först, ta bort gamla ingredienser
|
||||
await this.prisma.recipeIngredient.deleteMany({
|
||||
where: { recipeId: id },
|
||||
});
|
||||
|
||||
// Uppdatera receptet och lägg till nya ingredienser
|
||||
const recipe = await this.prisma.recipe.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name: updateRecipeDto.name,
|
||||
description: updateRecipeDto.description || null,
|
||||
instructions: updateRecipeDto.instructions || null,
|
||||
ingredients: {
|
||||
create: updateRecipeDto.ingredients.map((ingredient) => ({
|
||||
productId: ingredient.productId,
|
||||
quantity: ingredient.quantity.toString(),
|
||||
unit: ingredient.unit,
|
||||
note: ingredient.note || null,
|
||||
})),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
ingredients: {
|
||||
include: {
|
||||
product: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
async create(createRecipeDto: CreateRecipeDto) {
|
||||
const recipe = await this.prisma.recipe.create({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user