feat: migrate import functionality to microservice-importer for quick-import, receipt parsing, and markdown parsing

This commit is contained in:
Nils-Johan Gynther
2026-04-30 20:00:32 +02:00
parent 046791b63e
commit 797241f262
5 changed files with 256 additions and 378 deletions
+18 -1
View File
@@ -353,7 +353,24 @@ export class RecipesService {
}
async parseMarkdown(dto: ParseMarkdownDto) {
const parsed = parseRecipeMarkdown(dto.markdown);
// Delegera markdown-parsning till microservice-importer
const importerUrl = process.env.IMPORTER_SERVICE_URL || 'http://importer-api:3001';
let parsed: ParsedRecipe;
try {
const response = await fetch(`${importerUrl}/api/recipes/parse-markdown`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ markdown: dto.markdown }),
});
if (!response.ok) {
throw new Error(`Importer svarade ${response.status}`);
}
parsed = (await response.json()) as ParsedRecipe;
} catch (err) {
this.logger.error(`Kunde inte nå importer-api för parse-markdown: ${err}`);
// Fallback: använd lokal parser vid driftavbrott
parsed = parseRecipeMarkdown(dto.markdown);
}
const allProducts = await this.prisma.product.findMany({
where: { isActive: true },