diff --git a/app.js b/app.js index 78b7e7b..5006a7f 100644 --- a/app.js +++ b/app.js @@ -1417,8 +1417,10 @@ document.addEventListener('DOMContentLoaded', async () => { } console.log(result.message); - const fullName = `${vorname} ${nachname}`.trim(); - state.ownerStatuses[fullName] = status; + const fullName = `${vorname || ''} ${nachname || ''}`.trim(); + if (fullName) { + state.ownerStatuses[fullName] = status; + } const ownerLayerName = Object.keys(overlays).find(k => k.toLowerCase().includes('eigentümer')); if (ownerLayerName) { @@ -1503,8 +1505,12 @@ document.addEventListener('DOMContentLoaded', async () => { if (response.ok) { const statuses = await response.json(); statuses.forEach(s => { - const fullName = `${s.vorname} ${s.nachname}`.trim(); - state.ownerStatuses[fullName] = s.status; + const first = s.vorname || ''; + const last = s.nachname || ''; + const fullName = `${first} ${last}`.trim(); + if (fullName) { + state.ownerStatuses[fullName] = s.status; + } }); console.log(`${statuses.length} Eigentümer-Status geladen.`); @@ -1513,9 +1519,11 @@ document.addEventListener('DOMContentLoaded', async () => { if (ownerLayerName && overlays[ownerLayerName]) { overlays[ownerLayerName].setStyle(overlays[ownerLayerName].options.style); } + } else { + console.warn("API Fehler beim Laden der Status:", response.status); } } catch (err) { - console.error("Fehler beim Laden der Status:", err); + console.error("Netzwerkfehler beim Laden der Status:", err); } } diff --git a/server.js b/server.js index e6fd1d1..3830453 100644 --- a/server.js +++ b/server.js @@ -115,12 +115,19 @@ app.get('/api/wea/:projekt_id', async (req, res) => { // Hilfsfunktion zur Auflösung von Projekt-ID oder Name async function resolveProjectId(client, input) { + if (!input) return null; + // Prüfen, ob input eine valide UUID ist const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; if (uuidRegex.test(input)) return input; - // Sonst in der Projekte-Tabelle nach Name suchen - const res = await client.query('SELECT id FROM geodaten.projekte WHERE name = $1 OR name = $2', [input, input.toLowerCase()]); + // Normalisierte Suche (Kleinschreibung, Bindestriche zu Unterstrichen) + const normalized = input.toLowerCase().replace(/-/g, '_'); + + const res = await client.query( + 'SELECT id FROM geodaten.projekte WHERE LOWER(name) = $1 OR LOWER(REPLACE(name, \'-\', \'_\')) = $1', + [normalized] + ); return res.rows.length > 0 ? res.rows[0].id : null; }