feat: implement recipe analysis service and data models
Test Suite / test (24.15.0) (push) Has been cancelled

- Added RecipeAnalysisService to handle recipe ingredient analysis, including methods for checking ingredient availability and calculating quantities.
- Introduced new TypeScript definitions for recipe analysis results, including ingredient status and summary.
- Created corresponding Dart models for recipe analysis, including RecipeIngredientAnalysis, RecipeAnalysisSummary, and RecipeShoppingCandidate.
- Updated Flutter UI to reflect changes in ingredient availability status.
- Fixed color opacity issue in recipe image card.
This commit is contained in:
Nils-Johan Gynther
2026-05-06 07:54:03 +02:00
parent 969dafdbc6
commit 9fe85a719c
23 changed files with 1271 additions and 693 deletions
+50
View File
@@ -0,0 +1,50 @@
import { PrismaService } from '../prisma/prisma.service';
type AnalysisStatus = 'exact_match' | 'covered_by_pantry' | 'substitutable' | 'missing';
export declare class RecipeAnalysisService {
private readonly prisma;
constructor(prisma: PrismaService);
private getAccessibleRecipe;
private calculateAvailableQuantity;
analyzeRecipeIngredients(id: number, userId: number): Promise<{
recipeId: number;
ingredients: ({
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
note: any;
status: AnalysisStatus;
matchedProductId: any;
matchedProductName: any;
source: string;
availableQuantity: number;
missingQuantity: number;
} | {
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
note: any;
status: AnalysisStatus;
matchedProductId: any;
matchedProductName: any;
source: null;
availableQuantity: number;
missingQuantity: number;
})[];
summary: {
exactCount: number;
pantryCount: number;
substituteCount: number;
missingCount: number;
};
shoppingListCandidates: {
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
missingQuantity: number;
}[];
}>;
}
export {};
+217
View File
@@ -0,0 +1,217 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecipeAnalysisService = void 0;
const common_1 = require("@nestjs/common");
const prisma_service_1 = require("../prisma/prisma.service");
const units_1 = require("../common/utils/units");
let RecipeAnalysisService = class RecipeAnalysisService {
constructor(prisma) {
this.prisma = prisma;
}
async getAccessibleRecipe(id, userId) {
const recipe = await this.prisma.recipe.findFirst({
where: {
id,
OR: [
{ isPublic: true },
{ ownerId: userId },
{ shares: { some: { userId } } },
],
},
include: {
ingredients: {
include: {
product: true,
},
orderBy: { id: 'asc' },
},
},
});
if (!recipe) {
throw new common_1.NotFoundException(`Recipe with id ${id} not found`);
}
return recipe;
}
calculateAvailableQuantity(inventoryItems, requiredUnit) {
if (!requiredUnit) {
return inventoryItems.reduce((sum, item) => sum + Number(item.quantity ?? 0), 0);
}
const normalizedRequiredUnit = requiredUnit.trim().toLowerCase();
const sameUnit = inventoryItems
.filter((item) => item.unit.trim().toLowerCase() === normalizedRequiredUnit)
.reduce((sum, item) => sum + Number(item.quantity ?? 0), 0);
const converted = inventoryItems
.filter((item) => item.unit.trim().toLowerCase() !== normalizedRequiredUnit)
.reduce((sum, item) => {
if (!(0, units_1.canConvert)(item.unit, requiredUnit))
return sum;
try {
return sum + (0, units_1.convertUnit)(Number(item.quantity ?? 0), item.unit, requiredUnit);
}
catch {
return sum;
}
}, 0);
return sameUnit + converted;
}
async analyzeRecipeIngredients(id, userId) {
const recipe = await this.getAccessibleRecipe(id, userId);
const pantryItems = await this.prisma.pantryItem.findMany({
where: { userId },
select: { productId: true },
});
const pantryProductIds = new Set(pantryItems.map((p) => p.productId));
const ingredients = await Promise.all(recipe.ingredients.map(async (ingredient) => {
const requiredQuantity = Number(ingredient.quantity ?? 0);
const requiredUnit = (ingredient.unit ?? '').trim();
const rawName = (ingredient.rawName ?? '').trim() || 'Okänd ingrediens';
if (!ingredient.productId || !ingredient.product) {
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'missing',
matchedProductId: null,
matchedProductName: null,
source: null,
availableQuantity: 0,
missingQuantity: requiredQuantity,
};
}
if (pantryProductIds.has(ingredient.productId)) {
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'covered_by_pantry',
matchedProductId: ingredient.productId,
matchedProductName: ingredient.product.canonicalName || ingredient.product.name,
source: 'pantry',
availableQuantity: requiredQuantity,
missingQuantity: 0,
};
}
const inventoryItems = await this.prisma.inventoryItem.findMany({
where: { productId: ingredient.productId },
select: { quantity: true, unit: true },
});
const availableQuantity = this.calculateAvailableQuantity(inventoryItems, requiredUnit);
if (availableQuantity >= requiredQuantity) {
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'exact_match',
matchedProductId: ingredient.productId,
matchedProductName: ingredient.product.canonicalName || ingredient.product.name,
source: 'inventory',
availableQuantity,
missingQuantity: 0,
};
}
const alternativeProductIds = Array.isArray(ingredient.alternativeProductIds)
? ingredient.alternativeProductIds.filter((id) => typeof id === 'number')
: [];
for (const altProductId of alternativeProductIds) {
if (pantryProductIds.has(altProductId)) {
const altProduct = await this.prisma.product.findUnique({
where: { id: altProductId },
select: { id: true, name: true, canonicalName: true },
});
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'substitutable',
matchedProductId: altProduct?.id ?? altProductId,
matchedProductName: altProduct?.canonicalName || altProduct?.name || null,
source: 'pantry_substitute',
availableQuantity: requiredQuantity,
missingQuantity: 0,
};
}
const altInventoryItems = await this.prisma.inventoryItem.findMany({
where: { productId: altProductId },
select: { quantity: true, unit: true },
});
const altAvailable = this.calculateAvailableQuantity(altInventoryItems, requiredUnit);
if (altAvailable > 0) {
const altProduct = await this.prisma.product.findUnique({
where: { id: altProductId },
select: { id: true, name: true, canonicalName: true },
});
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'substitutable',
matchedProductId: altProduct?.id ?? altProductId,
matchedProductName: altProduct?.canonicalName || altProduct?.name || null,
source: 'inventory_substitute',
availableQuantity: altAvailable,
missingQuantity: Math.max(0, requiredQuantity - altAvailable),
};
}
}
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'missing',
matchedProductId: ingredient.productId,
matchedProductName: ingredient.product.canonicalName || ingredient.product.name,
source: null,
availableQuantity,
missingQuantity: Math.max(0, requiredQuantity - availableQuantity),
};
}));
const summary = {
exactCount: ingredients.filter((i) => i.status === 'exact_match').length,
pantryCount: ingredients.filter((i) => i.status === 'covered_by_pantry').length,
substituteCount: ingredients.filter((i) => i.status === 'substitutable').length,
missingCount: ingredients.filter((i) => i.status === 'missing').length,
};
const shoppingListCandidates = ingredients
.filter((i) => i.status === 'missing')
.map((i) => ({
ingredientId: i.ingredientId,
rawName: i.rawName,
quantity: i.quantity,
unit: i.unit,
missingQuantity: i.missingQuantity,
}));
return {
recipeId: recipe.id,
ingredients,
summary,
shoppingListCandidates,
};
}
};
exports.RecipeAnalysisService = RecipeAnalysisService;
exports.RecipeAnalysisService = RecipeAnalysisService = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
], RecipeAnalysisService);
//# sourceMappingURL=recipe-analysis.service.js.map
File diff suppressed because one or more lines are too long
+221 -176
View File
@@ -4,12 +4,14 @@ import { CreateIngredientDto } from './dto/create-ingredient.dto';
import { ParseMarkdownDto } from './dto/parse-markdown.dto';
import { ShareRecipeDto } from './dto/share-recipe.dto';
import { SetRecipeVisibilityDto } from './dto/set-recipe-visibility.dto';
import { RecipeAnalysisService } from './recipe-analysis.service';
declare class UpdateImageDto {
sourceUrl: string;
}
export declare class RecipesController {
private readonly recipesService;
constructor(recipesService: RecipesService);
private readonly recipeAnalysisService;
constructor(recipesService: RecipesService, recipeAnalysisService: RecipeAnalysisService);
parseMarkdown(dto: ParseMarkdownDto): Promise<{
name: string;
description: string;
@@ -43,6 +45,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -50,54 +54,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
})[]>;
getInventoryPreview(id: number, user: {
userId: number;
@@ -145,6 +147,49 @@ export declare class RecipesController {
pantryCount: number;
};
}>;
getRecipeAnalysis(id: number, user: {
userId: number;
}): Promise<{
recipeId: number;
ingredients: ({
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
note: any;
status: "missing" | "exact_match" | "covered_by_pantry" | "substitutable";
matchedProductId: any;
matchedProductName: any;
source: string;
availableQuantity: number;
missingQuantity: number;
} | {
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
note: any;
status: "missing" | "exact_match" | "covered_by_pantry" | "substitutable";
matchedProductId: any;
matchedProductName: any;
source: null;
availableQuantity: number;
missingQuantity: number;
})[];
summary: {
exactCount: number;
pantryCount: number;
substituteCount: number;
missingCount: number;
};
shoppingListCandidates: {
ingredientId: any;
rawName: any;
quantity: number;
unit: any;
missingQuantity: number;
}[];
}>;
findOne(id: number, user: {
userId: number;
}): Promise<{
@@ -155,6 +200,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -162,54 +209,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
create(createRecipeDto: CreateRecipeDto, user: {
userId: number;
@@ -217,6 +262,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -224,51 +271,49 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
update(id: number, createRecipeDto: CreateRecipeDto, user: {
userId: number;
@@ -276,6 +321,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -283,51 +330,49 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
remove(id: number, user: {
userId: number;
@@ -342,6 +387,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -349,60 +396,60 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
addIngredient(id: number, ingredient: CreateIngredientDto, user: {
userId: number;
}): Promise<{
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -410,38 +457,36 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
}>;
setVisibility(id: number, dto: SetRecipeVisibilityDto, user: {
@@ -454,6 +499,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -461,54 +508,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
shareRecipe(id: number, dto: ShareRecipeDto, user: {
userId: number;
@@ -520,6 +565,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -527,54 +574,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
unshareRecipe(id: number, username: string, user: {
userId: number;
@@ -586,6 +631,8 @@ export declare class RecipesController {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -593,54 +640,52 @@ export declare class RecipesController {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: import("@prisma/client/runtime/library").Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: import("@prisma/client/runtime/library").JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
}
export {};
+16 -2
View File
@@ -22,6 +22,7 @@ const parse_markdown_dto_1 = require("./dto/parse-markdown.dto");
const current_user_decorator_1 = require("../auth/decorators/current-user.decorator");
const share_recipe_dto_1 = require("./dto/share-recipe.dto");
const set_recipe_visibility_dto_1 = require("./dto/set-recipe-visibility.dto");
const recipe_analysis_service_1 = require("./recipe-analysis.service");
class UpdateImageDto {
}
__decorate([
@@ -29,8 +30,9 @@ __decorate([
__metadata("design:type", String)
], UpdateImageDto.prototype, "sourceUrl", void 0);
let RecipesController = class RecipesController {
constructor(recipesService) {
constructor(recipesService, recipeAnalysisService) {
this.recipesService = recipesService;
this.recipeAnalysisService = recipeAnalysisService;
}
parseMarkdown(dto) {
return this.recipesService.parseMarkdown(dto);
@@ -44,6 +46,9 @@ let RecipesController = class RecipesController {
getInventoryPreview(id, user) {
return this.recipesService.getInventoryPreview(id, user.userId);
}
getRecipeAnalysis(id, user) {
return this.recipeAnalysisService.analyzeRecipeIngredients(id, user.userId);
}
findOne(id, user) {
return this.recipesService.findOne(id, user.userId);
}
@@ -102,6 +107,14 @@ __decorate([
__metadata("design:paramtypes", [Number, Object]),
__metadata("design:returntype", void 0)
], RecipesController.prototype, "getInventoryPreview", null);
__decorate([
(0, common_1.Get)(':id/analysis'),
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
__param(1, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number, Object]),
__metadata("design:returntype", void 0)
], RecipesController.prototype, "getRecipeAnalysis", null);
__decorate([
(0, common_1.Get)(':id'),
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
@@ -183,6 +196,7 @@ __decorate([
], RecipesController.prototype, "unshareRecipe", null);
exports.RecipesController = RecipesController = __decorate([
(0, common_1.Controller)('recipes'),
__metadata("design:paramtypes", [recipes_service_1.RecipesService])
__metadata("design:paramtypes", [recipes_service_1.RecipesService,
recipe_analysis_service_1.RecipeAnalysisService])
], RecipesController);
//# sourceMappingURL=recipes.controller.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"recipes.controller.js","sourceRoot":"","sources":["../../src/recipes/recipes.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2G;AAC3G,qDAA2C;AAC3C,uDAAmD;AACnD,+DAA0D;AAC1D,uEAAkE;AAClE,iEAA4D;AAC5D,sFAAwE;AACxE,6DAAwD;AACxD,+EAAyE;AAEzE,MAAM,cAAc;CAGnB;AADC;IADC,IAAA,0BAAQ,GAAE;;iDACQ;AAId,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YAA6B,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAAG,CAAC;IAG/D,aAAa,CAAS,GAAqB;QACzC,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAChD,CAAC;IAGD,gBAAgB,CAAgB,IAAwB;QACtD,OAAO,IAAI,CAAC,cAAc,CAAC,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtE,CAAC;IAGD,OAAO,CAAgB,IAAwB;QAC7C,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAGD,mBAAmB,CACU,EAAU,EACtB,IAAwB;QAEvC,OAAO,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAClE,CAAC;IAGD,OAAO,CACsB,E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A;;6CADD,iCAAc;;oDAI5B;AAGK;IADL,IAAA,eAAM,EAAC,qBAAqB,CAAC;IAE3B,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,cAAK,EAAC,UAAU,CAAC,CAAA;IACjB,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;sDAGf;4BAlHU,iBAAiB;IAD7B,IAAA,mBAAU,EAAC,SAAS,CAAC;qCAGe,gCAAc;QACP,+CAAqB;GAHpD,iBAAiB,CAmH7B"}
+2 -1
View File
@@ -12,6 +12,7 @@ const prisma_module_1 = require("../prisma/prisma.module");
const ai_module_1 = require("../ai/ai.module");
const recipes_controller_1 = require("./recipes.controller");
const recipes_service_1 = require("./recipes.service");
const recipe_analysis_service_1 = require("./recipe-analysis.service");
let RecipesModule = class RecipesModule {
};
exports.RecipesModule = RecipesModule;
@@ -19,7 +20,7 @@ exports.RecipesModule = RecipesModule = __decorate([
(0, common_1.Module)({
imports: [prisma_module_1.PrismaModule, ai_module_1.AiModule],
controllers: [recipes_controller_1.RecipesController],
providers: [recipes_service_1.RecipesService],
providers: [recipes_service_1.RecipesService, recipe_analysis_service_1.RecipeAnalysisService],
})
], RecipesModule);
//# sourceMappingURL=recipes.module.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"recipes.module.js","sourceRoot":"","sources":["../../src/recipes/recipes.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAuD;AACvD,+CAA2C;AAC3C,6DAAyD;AACzD,uDAAmD;AAO5C,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IALzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,EAAE,oBAAQ,CAAC;QACjC,WAAW,EAAE,CAAC,sCAAiB,CAAC;QAChC,SAAS,EAAE,CAAC,gCAAc,CAAC;KAC5B,CAAC;GACW,aAAa,CAAG"}
{"version":3,"file":"recipes.module.js","sourceRoot":"","sources":["../../src/recipes/recipes.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAuD;AACvD,+CAA2C;AAC3C,6DAAyD;AACzD,uDAAmD;AACnD,uEAAkE;AAO3D,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IALzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,EAAE,oBAAQ,CAAC;QACjC,WAAW,EAAE,CAAC,sCAAiB,CAAC;QAChC,SAAS,EAAE,CAAC,gCAAc,EAAE,+CAAqB,CAAC;KACnD,CAAC;GACW,aAAa,CAAG"}
+176 -175
View File
@@ -17,6 +17,7 @@ export declare class RecipesService {
private readonly logger;
constructor(prisma: PrismaService, aiService: AiService);
private throwRecipeNotFound;
private normalizeIngredientName;
private assertProductsActive;
private findRecipeByIdOrThrow;
private assertAndClaimRecipeOwner;
@@ -73,6 +74,8 @@ export declare class RecipesService {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -80,54 +83,52 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
})[]>;
findOne(id: number, userId: number): Promise<{
owner: {
@@ -137,6 +138,8 @@ export declare class RecipesService {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -144,59 +147,59 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
update(id: number, updateRecipeDto: CreateRecipeDto, userId: number): Promise<{
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -204,51 +207,49 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
remove(id: number, userId: number): Promise<void>;
updateImage(id: number, sourceUrl: string, userId: number): Promise<{
@@ -259,6 +260,8 @@ export declare class RecipesService {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -266,54 +269,52 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
setVisibility(id: number, userId: number, isPublic: boolean): Promise<{
owner: {
@@ -323,6 +324,8 @@ export declare class RecipesService {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -330,54 +333,52 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
shareWithUser(id: number, ownerId: number, username: string): Promise<{
owner: {
@@ -387,6 +388,8 @@ export declare class RecipesService {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -394,54 +397,52 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
unshareWithUser(id: number, ownerId: number, username: string): Promise<{
owner: {
@@ -451,6 +452,8 @@ export declare class RecipesService {
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -458,59 +461,59 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
shares: {
userId: number;
}[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
create(createRecipeDto: CreateRecipeDto, userId: number): Promise<{
ingredients: ({
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -518,55 +521,55 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
})[];
} & {
isPublic: boolean;
name: string;
id: number;
createdAt: Date;
updatedAt: Date;
ownerId: number | null;
name: string;
description: string | null;
instructions: string | null;
imageUrl: string | null;
servings: number | null;
isPublic: boolean;
ownerId: number | null;
createdAt: Date;
updatedAt: Date;
}>;
addIngredient(id: number, ingredient: CreateIngredientDto, userId: number): Promise<{
product: ({
nutrition: {
id: number;
productId: number;
calories: number | null;
protein: number | null;
fat: number | null;
@@ -574,38 +577,36 @@ export declare class RecipesService {
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
} & {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
name: string;
ownerId: number;
createdAt: Date;
updatedAt: Date;
ownerId: number;
status: string;
normalizedName: string;
category: string | null;
canonicalName: string | null;
isActive: boolean;
deletedAt: Date | null;
categoryId: number | null;
isPrivate: boolean;
}) | null;
} & {
id: number;
createdAt: Date;
updatedAt: Date;
recipeId: number;
productId: number | null;
quantity: Prisma.Decimal | null;
unit: string | null;
rawName: string;
rawLine: string | null;
quantity: Prisma.Decimal | null;
unit: string | null;
note: string | null;
alternativeProductIds: Prisma.JsonValue | null;
matchConfidence: number | null;
matchSource: string | null;
alternativeProductIds: Prisma.JsonValue | null;
recipeId: number;
analysisStatus: string | null;
}>;
suggestRecipesFromInventory(userId: number): Promise<{
+8 -2
View File
@@ -29,6 +29,12 @@ let RecipesService = RecipesService_1 = class RecipesService {
throwRecipeNotFound(id) {
throw new common_1.NotFoundException(`Recipe with id ${id} not found`);
}
normalizeIngredientName(value) {
const trimmed = value.trim();
if (!trimmed)
return trimmed;
return `${trimmed.charAt(0).toUpperCase()}${trimmed.slice(1)}`;
}
async assertProductsActive(productIds) {
if (productIds.length === 0)
return;
@@ -299,7 +305,7 @@ let RecipesService = RecipesService_1 = class RecipesService {
ingredients: {
create: updateRecipeDto.ingredients.map((ingredient) => ({
productId: ingredient.productId ?? null,
rawName: ingredient.rawName,
rawName: this.normalizeIngredientName(ingredient.rawName),
rawLine: ingredient.rawLine ?? null,
quantity: ingredient.quantity ?? null,
unit: ingredient.unit?.trim() ? ingredient.unit : null,
@@ -443,7 +449,7 @@ let RecipesService = RecipesService_1 = class RecipesService {
ingredients: {
create: createRecipeDto.ingredients.map((ingredient) => ({
productId: ingredient.productId ?? null,
rawName: ingredient.rawName,
rawName: this.normalizeIngredientName(ingredient.rawName),
rawLine: ingredient.rawLine ?? null,
quantity: ingredient.quantity ?? null,
unit: ingredient.unit?.trim() ? ingredient.unit : null,
File diff suppressed because one or more lines are too long
@@ -0,0 +1,228 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { canConvert, convertUnit } from '../common/utils/units';
type AnalysisStatus = 'exact_match' | 'covered_by_pantry' | 'substitutable' | 'missing';
@Injectable()
export class RecipeAnalysisService {
constructor(private readonly prisma: PrismaService) {}
private async getAccessibleRecipe(id: number, userId: number) {
const recipe = await this.prisma.recipe.findFirst({
where: {
id,
OR: [
{ isPublic: true },
{ ownerId: userId },
{ shares: { some: { userId } } },
],
},
include: {
ingredients: {
include: {
product: true,
},
orderBy: { id: 'asc' },
},
},
});
if (!recipe) {
throw new NotFoundException(`Recipe with id ${id} not found`);
}
return recipe;
}
private calculateAvailableQuantity(
inventoryItems: Array<{ quantity: any; unit: string }>,
requiredUnit: string,
): number {
if (!requiredUnit) {
return inventoryItems.reduce((sum, item) => sum + Number(item.quantity ?? 0), 0);
}
const normalizedRequiredUnit = requiredUnit.trim().toLowerCase();
const sameUnit = inventoryItems
.filter((item) => item.unit.trim().toLowerCase() === normalizedRequiredUnit)
.reduce((sum, item) => sum + Number(item.quantity ?? 0), 0);
const converted = inventoryItems
.filter((item) => item.unit.trim().toLowerCase() !== normalizedRequiredUnit)
.reduce((sum, item) => {
if (!canConvert(item.unit, requiredUnit)) return sum;
try {
return sum + convertUnit(Number(item.quantity ?? 0), item.unit, requiredUnit);
} catch {
return sum;
}
}, 0);
return sameUnit + converted;
}
async analyzeRecipeIngredients(id: number, userId: number) {
const recipe = await this.getAccessibleRecipe(id, userId);
const pantryItems = await this.prisma.pantryItem.findMany({
where: { userId },
select: { productId: true },
});
const pantryProductIds = new Set(pantryItems.map((p) => p.productId));
const ingredients = await Promise.all(
recipe.ingredients.map(async (ingredient: any) => {
const requiredQuantity = Number(ingredient.quantity ?? 0);
const requiredUnit = (ingredient.unit ?? '').trim();
const rawName = (ingredient.rawName ?? '').trim() || 'Okänd ingrediens';
if (!ingredient.productId || !ingredient.product) {
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'missing' as AnalysisStatus,
matchedProductId: null,
matchedProductName: null,
source: null,
availableQuantity: 0,
missingQuantity: requiredQuantity,
};
}
if (pantryProductIds.has(ingredient.productId)) {
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'covered_by_pantry' as AnalysisStatus,
matchedProductId: ingredient.productId,
matchedProductName: ingredient.product.canonicalName || ingredient.product.name,
source: 'pantry',
availableQuantity: requiredQuantity,
missingQuantity: 0,
};
}
const inventoryItems = await this.prisma.inventoryItem.findMany({
where: { productId: ingredient.productId },
select: { quantity: true, unit: true },
});
const availableQuantity = this.calculateAvailableQuantity(inventoryItems, requiredUnit);
if (availableQuantity >= requiredQuantity) {
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'exact_match' as AnalysisStatus,
matchedProductId: ingredient.productId,
matchedProductName: ingredient.product.canonicalName || ingredient.product.name,
source: 'inventory',
availableQuantity,
missingQuantity: 0,
};
}
const alternativeProductIds = Array.isArray(ingredient.alternativeProductIds)
? ingredient.alternativeProductIds.filter((id: any) => typeof id === 'number')
: [];
for (const altProductId of alternativeProductIds) {
if (pantryProductIds.has(altProductId)) {
const altProduct = await this.prisma.product.findUnique({
where: { id: altProductId },
select: { id: true, name: true, canonicalName: true },
});
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'substitutable' as AnalysisStatus,
matchedProductId: altProduct?.id ?? altProductId,
matchedProductName: altProduct?.canonicalName || altProduct?.name || null,
source: 'pantry_substitute',
availableQuantity: requiredQuantity,
missingQuantity: 0,
};
}
const altInventoryItems = await this.prisma.inventoryItem.findMany({
where: { productId: altProductId },
select: { quantity: true, unit: true },
});
const altAvailable = this.calculateAvailableQuantity(altInventoryItems, requiredUnit);
if (altAvailable > 0) {
const altProduct = await this.prisma.product.findUnique({
where: { id: altProductId },
select: { id: true, name: true, canonicalName: true },
});
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'substitutable' as AnalysisStatus,
matchedProductId: altProduct?.id ?? altProductId,
matchedProductName: altProduct?.canonicalName || altProduct?.name || null,
source: 'inventory_substitute',
availableQuantity: altAvailable,
missingQuantity: Math.max(0, requiredQuantity - altAvailable),
};
}
}
return {
ingredientId: ingredient.id,
rawName,
quantity: requiredQuantity,
unit: requiredUnit,
note: ingredient.note ?? null,
status: 'missing' as AnalysisStatus,
matchedProductId: ingredient.productId,
matchedProductName: ingredient.product.canonicalName || ingredient.product.name,
source: null,
availableQuantity,
missingQuantity: Math.max(0, requiredQuantity - availableQuantity),
};
}),
);
const summary = {
exactCount: ingredients.filter((i) => i.status === 'exact_match').length,
pantryCount: ingredients.filter((i) => i.status === 'covered_by_pantry').length,
substituteCount: ingredients.filter((i) => i.status === 'substitutable').length,
missingCount: ingredients.filter((i) => i.status === 'missing').length,
};
const shoppingListCandidates = ingredients
.filter((i) => i.status === 'missing')
.map((i) => ({
ingredientId: i.ingredientId,
rawName: i.rawName,
quantity: i.quantity,
unit: i.unit,
missingQuantity: i.missingQuantity,
}));
return {
recipeId: recipe.id,
ingredients,
summary,
shoppingListCandidates,
};
}
}
+13 -1
View File
@@ -7,6 +7,7 @@ import { ParseMarkdownDto } from './dto/parse-markdown.dto';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
import { ShareRecipeDto } from './dto/share-recipe.dto';
import { SetRecipeVisibilityDto } from './dto/set-recipe-visibility.dto';
import { RecipeAnalysisService } from './recipe-analysis.service';
class UpdateImageDto {
@IsString()
@@ -15,7 +16,10 @@ class UpdateImageDto {
@Controller('recipes')
export class RecipesController {
constructor(private readonly recipesService: RecipesService) {}
constructor(
private readonly recipesService: RecipesService,
private readonly recipeAnalysisService: RecipeAnalysisService,
) {}
@Post('parse-markdown')
parseMarkdown(@Body() dto: ParseMarkdownDto) {
@@ -40,6 +44,14 @@ export class RecipesController {
return this.recipesService.getInventoryPreview(id, user.userId);
}
@Get(':id/analysis')
getRecipeAnalysis(
@Param('id', ParseIntPipe) id: number,
@CurrentUser() user: { userId: number },
) {
return this.recipeAnalysisService.analyzeRecipeIngredients(id, user.userId);
}
@Get(':id')
findOne(
@Param('id', ParseIntPipe) id: number,
+2 -1
View File
@@ -3,10 +3,11 @@ import { PrismaModule } from '../prisma/prisma.module';
import { AiModule } from '../ai/ai.module';
import { RecipesController } from './recipes.controller';
import { RecipesService } from './recipes.service';
import { RecipeAnalysisService } from './recipe-analysis.service';
@Module({
imports: [PrismaModule, AiModule],
controllers: [RecipesController],
providers: [RecipesService],
providers: [RecipesService, RecipeAnalysisService],
})
export class RecipesModule {}
+8 -2
View File
@@ -34,6 +34,12 @@ export class RecipesService {
throw new NotFoundException(`Recipe with id ${id} not found`);
}
private normalizeIngredientName(value: string): string {
const trimmed = value.trim();
if (!trimmed) return trimmed;
return `${trimmed.charAt(0).toUpperCase()}${trimmed.slice(1)}`;
}
private async assertProductsActive(productIds: number[]): Promise<void> {
if (productIds.length === 0) return;
const activeProducts = await this.prisma.product.findMany({
@@ -361,7 +367,7 @@ export class RecipesService {
ingredients: {
create: updateRecipeDto.ingredients.map((ingredient) => ({
productId: ingredient.productId ?? null,
rawName: ingredient.rawName,
rawName: this.normalizeIngredientName(ingredient.rawName),
rawLine: ingredient.rawLine ?? null,
quantity: ingredient.quantity ?? null,
unit: ingredient.unit?.trim() ? ingredient.unit : null,
@@ -537,7 +543,7 @@ export class RecipesService {
ingredients: {
create: createRecipeDto.ingredients.map((ingredient) => ({
productId: ingredient.productId ?? null,
rawName: ingredient.rawName,
rawName: this.normalizeIngredientName(ingredient.rawName),
rawLine: ingredient.rawLine ?? null,
quantity: ingredient.quantity ?? null,
unit: ingredient.unit?.trim() ? ingredient.unit : null,
File diff suppressed because one or more lines are too long