Add recipe deletion functionality and enhance inventory consumption details

This commit is contained in:
Nils-Johan Gynther
2026-04-10 18:44:06 +02:00
parent a743f832a2
commit dd17656e4c
7 changed files with 174 additions and 49 deletions
@@ -94,6 +94,16 @@ export class InventoryService {
where: {
inventoryItemId: id,
},
select: {
id: true,
inventoryItemId: true,
amountUsed: true,
comment: true,
createdAt: true,
inventoryItem: {
select: { unit: true },
},
},
orderBy: {
createdAt: 'desc',
},
+7 -1
View File
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Param, ParseIntPipe, Post, Patch } from '@nestjs/common';
import { Body, Controller, Delete, Get, HttpCode, Param, ParseIntPipe, Post, Patch } from '@nestjs/common';
import { RecipesService } from './recipes.service';
import { CreateRecipeDto } from './dto/create-recipe.dto';
@@ -33,4 +33,10 @@ export class RecipesController {
) {
return this.recipesService.update(id, createRecipeDto);
}
@Delete(':id')
@HttpCode(204)
async remove(@Param('id', ParseIntPipe) id: number) {
return this.recipesService.remove(id);
}
}
+13
View File
@@ -345,6 +345,19 @@ export class RecipesService {
return recipe;
}
async remove(id: number) {
const existingRecipe = await this.prisma.recipe.findUnique({
where: { id },
});
if (!existingRecipe) {
throw new NotFoundException(`Recipe with id ${id} not found`);
}
await this.prisma.recipeIngredient.deleteMany({ where: { recipeId: id } });
await this.prisma.recipe.delete({ where: { id } });
}
async create(createRecipeDto: CreateRecipeDto) {
const recipe = await this.prisma.recipe.create({
data: {