feat: Add standalone script for enhanced Bygma CSV import with validation test: Create simple database test to show current state and product counts test: Develop enhanced validation demo to simulate problematic CSV data handling test: Implement price validation tests with higher limits for edge cases test: Conduct real enhanced validation test with actual Bygma CSV file test: Test validation improvements with known problematic data test: Validate logic of cleaning and validating CSV rows without database test: Test improved VareNr cleaning functionality to remove spaces
54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
const BygmaPrisbogImportService = require('./backend/src/services/bygmaPrisbogImportService');
|
|
const databaseService = require('./backend/src/services/databaseService');
|
|
|
|
async function debugImportWarnings() {
|
|
console.log('🔍 Debugging import warnings...');
|
|
|
|
const importService = new BygmaPrisbogImportService();
|
|
|
|
try {
|
|
// Clear previous imports for fresh debug
|
|
await databaseService.query('DELETE FROM bygma_products');
|
|
await databaseService.query('DELETE FROM bygma_price_history');
|
|
console.log('📊 Cleared database for fresh debug run');
|
|
|
|
// Run import with enhanced logging
|
|
const filePath = './Bygma-Prisbog-DK-1000070-20241201-093000.csv';
|
|
const result = await importService.importFromCSV(filePath);
|
|
|
|
console.log('\n📈 Import Results:');
|
|
console.log(` - Total rows: ${result.stats.totalRows}`);
|
|
console.log(` - Successful: ${result.stats.successfulRows}`);
|
|
console.log(` - Failed: ${result.stats.failedRows}`);
|
|
console.log(` - New products: ${result.stats.newProducts}`);
|
|
console.log(` - Updated prices: ${result.stats.updatedPrices}`);
|
|
|
|
if (result.errors.length > 0) {
|
|
console.log('\n⚠️ First 20 errors:');
|
|
result.errors.slice(0, 20).forEach((error, index) => {
|
|
console.log(`${index + 1}. Line ${error.line}: ${error.error}`);
|
|
console.log(` Data: ${JSON.stringify(error.data).substring(0, 200)}...`);
|
|
});
|
|
|
|
// Analyze error patterns
|
|
console.log('\n📊 Error Analysis:');
|
|
const errorTypes = {};
|
|
result.errors.forEach(error => {
|
|
const errorType = error.error.split(':')[0] || error.error;
|
|
errorTypes[errorType] = (errorTypes[errorType] || 0) + 1;
|
|
});
|
|
|
|
Object.entries(errorTypes).forEach(([type, count]) => {
|
|
console.log(` - ${type}: ${count} occurrences`);
|
|
});
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ Debug failed:', error.message);
|
|
} finally {
|
|
await databaseService.close();
|
|
}
|
|
}
|
|
|
|
debugImportWarnings();
|