Refactor logging in IcaRecipeParser and QuickImportService to use NestJS Logger
- Updated IcaRecipeParser to replace console.log statements with Logger for better logging practices. - Enhanced QuickImportService with Logger for consistent logging and error handling. - Changed quantity validation in CreateRecipeIngredientDto and CreateRecipeDto to allow zero. - Removed CanonicalNameForm and NameForm components from the frontend. - Updated EditProductForm to use a select dropdown for categories instead of a text input. - Added validation for product name, canonical name, and category length in product update action. - Refactored unit options into a separate file for better reusability across components. - Removed unused API fetching functions and inventory types to clean up the codebase.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { RecipeParser, ParsedRecipe } from './base.parser';
|
||||
|
||||
/**
|
||||
@@ -6,13 +7,14 @@ import { RecipeParser, ParsedRecipe } from './base.parser';
|
||||
* Denna är mer permissiv än site-specifika parsers
|
||||
*/
|
||||
export class GenericRecipeParser extends RecipeParser {
|
||||
private readonly logger = new Logger(GenericRecipeParser.name);
|
||||
canHandle(url: string): boolean {
|
||||
// Denna parser hanterar alltid (är fallback)
|
||||
return true;
|
||||
}
|
||||
|
||||
parse(html: string): ParsedRecipe {
|
||||
console.log('[GenericParser] Parsing recipe from unknown site...');
|
||||
this.logger.log('Parsing recipe from unknown site...');
|
||||
|
||||
// Extrahera og:image för bildurl-fallback
|
||||
const ogImage = this.extractOgImage(html);
|
||||
@@ -31,15 +33,15 @@ export class GenericRecipeParser extends RecipeParser {
|
||||
: jsonData['@graph']?.find((item: any) => item['@type'] === 'Recipe');
|
||||
|
||||
if (recipe) {
|
||||
console.log('[GenericParser] ✓ JSON-LD data found');
|
||||
this.logger.log('JSON-LD data found');
|
||||
return this.extractFromJsonLd(recipe, ogImage);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('[GenericParser] JSON-LD parsing failed');
|
||||
this.logger.warn('JSON-LD parsing failed');
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[GenericParser] No JSON-LD found, using HTML parsing');
|
||||
this.logger.log('No JSON-LD found, using HTML parsing');
|
||||
return this.parseFromHtml(html, ogImage);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { RecipeParser, ParsedRecipe } from './base.parser';
|
||||
|
||||
/**
|
||||
@@ -5,12 +6,13 @@ import { RecipeParser, ParsedRecipe } from './base.parser';
|
||||
* Använder JSON-LD structured data som primär källa
|
||||
*/
|
||||
export class IcaRecipeParser extends RecipeParser {
|
||||
private readonly logger = new Logger(IcaRecipeParser.name);
|
||||
canHandle(url: string): boolean {
|
||||
return /ica\.se\/recept/i.test(url);
|
||||
}
|
||||
|
||||
parse(html: string): ParsedRecipe {
|
||||
console.log('[IcaParser] Parsing ICA recipe...');
|
||||
this.logger.log('Parsing ICA recipe...');
|
||||
|
||||
// Extrahera og:image för bildurl-fallback
|
||||
const ogImage = this.extractOgImage(html);
|
||||
@@ -31,16 +33,16 @@ export class IcaRecipeParser extends RecipeParser {
|
||||
: jsonData['@graph']?.find((item: any) => item['@type'] === 'Recipe');
|
||||
|
||||
if (recipe) {
|
||||
console.log('[IcaParser] ✓ JSON-LD recipe found');
|
||||
this.logger.log('JSON-LD recipe found');
|
||||
return this.extractFromJsonLd(recipe, ogImage);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('[IcaParser] JSON-LD parsing failed:', err);
|
||||
this.logger.warn(`JSON-LD parsing failed: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: HTML parsing (sällan nödvändigt för ICA)
|
||||
console.log('[IcaParser] Falling back to HTML parsing');
|
||||
this.logger.log('Falling back to HTML parsing');
|
||||
return this.parseFromHtml(html, ogImage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user