feat: add functionality to manually add ingredients; implement CreateIngredientDto and update RecipesController and RecipesService
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -4,6 +4,7 @@ import * as fs from 'node:fs/promises';
|
||||
import * as path from 'node:path';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CreateRecipeDto } from './dto/create-recipe.dto';
|
||||
import { CreateIngredientDto } from './dto/create-ingredient.dto';
|
||||
import { ParseMarkdownDto } from './dto/parse-markdown.dto';
|
||||
import { downloadAndOptimizeImage } from '../common/utils/download-image';
|
||||
import { parseRecipeMarkdown, ParsedRecipe, ParsedIngredient } from '../common/utils/recipe-parser';
|
||||
@@ -475,6 +476,25 @@ export class RecipesService {
|
||||
}
|
||||
}
|
||||
|
||||
async addIngredient(id: number, ingredient: CreateIngredientDto, userId: number) {
|
||||
const recipe = await this.findRecipeByIdOrThrow(id);
|
||||
await this.assertRecipeOwnedByUser(recipe, userId, id);
|
||||
await this.assertProductsActive([ingredient.productId]);
|
||||
|
||||
return this.prisma.recipeIngredient.create({
|
||||
data: {
|
||||
productId: ingredient.productId,
|
||||
quantity: ingredient.quantity,
|
||||
unit: ingredient.unit,
|
||||
note: ingredient.note || null,
|
||||
recipeId: id,
|
||||
},
|
||||
include: {
|
||||
product: { include: { nutrition: true } },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async parseMarkdown(dto: ParseMarkdownDto) {
|
||||
// Delegera markdown-parsning till microservice-importer
|
||||
const importerUrl = process.env.IMPORTER_SERVICE_URL || 'http://importer-api:3001';
|
||||
|
||||
Reference in New Issue
Block a user