Initial commit - Stand 26.04.2026
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
// Import über REST-API statt direkt zu PostgreSQL
|
||||
|
||||
const API_URL = 'http://192.168.0.141:3001/api';
|
||||
|
||||
// Test-Einheit: Brandt 2023
|
||||
const testData = {
|
||||
jahr: 2023,
|
||||
wohnung: 'Zingelstr. 14',
|
||||
mieter: 'Yvonne Brandt',
|
||||
kaltmiete: 0,
|
||||
nebenkosten: 501.48, // Summe aus Excel
|
||||
versicherung: 129.58, // Geb. Vers./Haftpflichtv.
|
||||
heizkosten: 102.53, // Wartung Heizung
|
||||
wasser: 0,
|
||||
muell: 153.85, // Müllabfuhr
|
||||
sonstiges: 115.53 // Grundsteuer (40.17) + Niederschlagwasser (75.36)
|
||||
};
|
||||
|
||||
async function apiCall(endpoint, options = {}) {
|
||||
const url = `${API_URL}${endpoint}`;
|
||||
const config = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
},
|
||||
...options,
|
||||
};
|
||||
|
||||
if (options.body && typeof options.body === 'object') {
|
||||
config.body = JSON.stringify(options.body);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(url, config);
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: 'Unknown error' }));
|
||||
throw new Error(error.error || `HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error(`API Error (${endpoint}):`, error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function importTest() {
|
||||
console.log('=== TEST-IMPORT: Yvonne Brandt 2023 ===\n');
|
||||
console.log('=== ZU IMPORTIERENDE DATEN ===');
|
||||
console.log(JSON.stringify(testData, null, 2));
|
||||
|
||||
console.log('\n=== FÜHRE IMPORT AUS ===');
|
||||
|
||||
try {
|
||||
// Erst prüfen, ob Eintrag existiert
|
||||
const existing = await apiCall('/nebenkosten');
|
||||
const brandtEntries = existing.filter(e => e.mieter && e.mieter.includes('Brandt'));
|
||||
console.log(`Gefunden: ${brandtEntries.length} Einträge für Brandt`);
|
||||
brandtEntries.forEach(e => {
|
||||
console.log(` - ${e.jahr}: ${e.mieter} (${e.nebenkosten} €)`);
|
||||
});
|
||||
|
||||
// Import
|
||||
const result = await apiCall('/nebenkosten', {
|
||||
method: 'POST',
|
||||
body: testData
|
||||
});
|
||||
|
||||
console.log('\n✓ ERFOLGREICH IMPORTIERT:');
|
||||
console.log(' ID:', result.id);
|
||||
console.log(' Jahr:', result.jahr);
|
||||
console.log(' Wohnung:', result.wohnung);
|
||||
console.log(' Mieter:', result.mieter);
|
||||
console.log(' Nebenkosten:', result.nebenkosten, '€');
|
||||
console.log(' Versicherung:', result.versicherung, '€');
|
||||
console.log(' Heizkosten:', result.heizkosten, '€');
|
||||
console.log(' Müll:', result.muell, '€');
|
||||
console.log(' Sonstiges:', result.sonstiges, '€');
|
||||
|
||||
// Verifizieren
|
||||
const verify = await apiCall('/nebenkosten');
|
||||
const imported = verify.find(e => e.id === result.id);
|
||||
|
||||
console.log('\n=== VERIFIZIERUNG ===');
|
||||
if (imported) {
|
||||
console.log('✓ Datensatz in Datenbank bestätigt');
|
||||
console.log(' ID:', imported.id);
|
||||
console.log(' Mieter:', imported.mieter);
|
||||
console.log(' Jahr:', imported.jahr);
|
||||
console.log(' Gesamtkosten:', imported.nebenkosten, '€');
|
||||
} else {
|
||||
console.log('✗ Datensatz nicht gefunden!');
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ FEHLER beim Import:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Führe Import aus
|
||||
importTest().catch(err => {
|
||||
console.error('\nImport fehlgeschlagen:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user