feat: migrate import functionality to microservice-importer for quick-import, receipt parsing, and markdown parsing
This commit is contained in:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user