Enhance CSV import functionality with improved error messaging and logging
- Updated error message in CSVImportPanel to include a period for better readability. - Added console logs in the CSV import API route to track the import process and precheck status. - Removed redundant validation for 'Beguenstigter/Zahlungspflichtiger' to streamline error handling during CSV import.
This commit is contained in:
@@ -457,7 +457,7 @@ class CSVImportPanel extends Component {
|
|||||||
)}
|
)}
|
||||||
{importResult.errors > 0 && (
|
{importResult.errors > 0 && (
|
||||||
<Typography variant="body1" color="warning.main">
|
<Typography variant="body1" color="warning.main">
|
||||||
<strong>Fehler:</strong> {importResult.errors} Zeilen konnten nicht verarbeitet werden
|
<strong>Fehler:</strong> {importResult.errors} Zeilen konnten nicht verarbeitet werden.
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
{importResult.message && (
|
{importResult.message && (
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ router.post('/test-csv-import', async (req, res) => {
|
|||||||
|
|
||||||
// Import CSV transactions to database
|
// Import CSV transactions to database
|
||||||
router.post('/import-csv-transactions', authenticateToken, async (req, res) => {
|
router.post('/import-csv-transactions', authenticateToken, async (req, res) => {
|
||||||
|
console.log('Importing CSV transactions');
|
||||||
try {
|
try {
|
||||||
const { executeQuery } = require('../../config/database');
|
const { executeQuery } = require('../../config/database');
|
||||||
const { transactions, filename, batchId, headers } = req.body;
|
const { transactions, filename, batchId, headers } = req.body;
|
||||||
@@ -180,6 +181,7 @@ router.post('/import-csv-transactions', authenticateToken, async (req, res) => {
|
|||||||
let successCount = 0;
|
let successCount = 0;
|
||||||
let errorCount = 0;
|
let errorCount = 0;
|
||||||
const errors = [];
|
const errors = [];
|
||||||
|
console.log('precheck done');
|
||||||
|
|
||||||
for (let i = 0; i < transactions.length; i++) {
|
for (let i = 0; i < transactions.length; i++) {
|
||||||
const transaction = transactions[i];
|
const transaction = transactions[i];
|
||||||
@@ -195,9 +197,6 @@ router.post('/import-csv-transactions', authenticateToken, async (req, res) => {
|
|||||||
validationErrors.push('Betrag is required');
|
validationErrors.push('Betrag is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!transaction['Beguenstigter/Zahlungspflichtiger'] || transaction['Beguenstigter/Zahlungspflichtiger'].trim() === '') {
|
|
||||||
validationErrors.push('Beguenstigter/Zahlungspflichtiger is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validationErrors.length > 2) {
|
if (validationErrors.length > 2) {
|
||||||
console.log('Skipping invalid row ' + (i + 1) + ':', validationErrors);
|
console.log('Skipping invalid row ' + (i + 1) + ':', validationErrors);
|
||||||
@@ -287,6 +286,8 @@ router.post('/import-csv-transactions', authenticateToken, async (req, res) => {
|
|||||||
errorCount++;
|
errorCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('import done',errors);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user