feat: add servings field to Recipe model and implement inventory comparison functionality

This commit is contained in:
Nils-Johan Gynther
2026-04-17 18:48:08 +02:00
parent 8a86b0aebd
commit 8e0aed032c
10 changed files with 260 additions and 20 deletions
+9 -4
View File
@@ -1,12 +1,12 @@
import {
IsArray,
IsOptional,
IsString,
ValidateNested,
ArrayMinSize,
IsInt,
IsNumber,
IsOptional,
IsString,
Min,
ValidateNested,
ArrayMinSize,
} from 'class-validator';
import { Type } from 'class-transformer';
@@ -42,6 +42,11 @@ export class CreateRecipeDto {
@IsString()
imageUrl?: string;
@IsOptional()
@IsInt()
@Min(1)
servings?: number;
@IsArray()
@ArrayMinSize(1)
@ValidateNested({ each: true })
+7 -5
View File
@@ -295,7 +295,7 @@ export class RecipesService {
include: {
ingredients: {
include: {
product: true,
product: { include: { nutrition: true } },
},
},
},
@@ -308,7 +308,7 @@ export class RecipesService {
include: {
ingredients: {
include: {
product: true,
product: { include: { nutrition: true } },
},
},
},
@@ -343,6 +343,7 @@ export class RecipesService {
name: updateRecipeDto.name,
description: updateRecipeDto.description || null,
instructions: updateRecipeDto.instructions || null,
servings: updateRecipeDto.servings ?? null,
...(updateRecipeDto.imageUrl !== undefined && { imageUrl: updateRecipeDto.imageUrl || null }),
ingredients: {
create: updateRecipeDto.ingredients.map((ingredient) => ({
@@ -356,7 +357,7 @@ export class RecipesService {
include: {
ingredients: {
include: {
product: true,
product: { include: { nutrition: true } },
},
},
},
@@ -389,7 +390,7 @@ export class RecipesService {
return this.prisma.recipe.update({
where: { id },
data: { imageUrl },
include: { ingredients: { include: { product: true } } },
include: { ingredients: { include: { product: { include: { nutrition: true } } } } },
});
}
@@ -411,6 +412,7 @@ export class RecipesService {
description: createRecipeDto.description || null,
instructions: createRecipeDto.instructions || null,
imageUrl,
servings: createRecipeDto.servings ?? null,
ingredients: {
create: createRecipeDto.ingredients.map((ingredient) => ({
productId: ingredient.productId,
@@ -423,7 +425,7 @@ export class RecipesService {
include: {
ingredients: {
include: {
product: true,
product: { include: { nutrition: true } },
},
},
},