Fix project ID resolution and null name concatenation
Deploy Bürgerwind / deploy (push) Successful in 16s Details

This commit is contained in:
Johannes Baumeister 2026-04-29 21:05:05 +02:00
parent b824c8ea73
commit 9c8032d511
2 changed files with 22 additions and 7 deletions

18
app.js
View File

@ -1417,8 +1417,10 @@ document.addEventListener('DOMContentLoaded', async () => {
} }
console.log(result.message); console.log(result.message);
const fullName = `${vorname} ${nachname}`.trim(); const fullName = `${vorname || ''} ${nachname || ''}`.trim();
state.ownerStatuses[fullName] = status; if (fullName) {
state.ownerStatuses[fullName] = status;
}
const ownerLayerName = Object.keys(overlays).find(k => k.toLowerCase().includes('eigentümer')); const ownerLayerName = Object.keys(overlays).find(k => k.toLowerCase().includes('eigentümer'));
if (ownerLayerName) { if (ownerLayerName) {
@ -1503,8 +1505,12 @@ document.addEventListener('DOMContentLoaded', async () => {
if (response.ok) { if (response.ok) {
const statuses = await response.json(); const statuses = await response.json();
statuses.forEach(s => { statuses.forEach(s => {
const fullName = `${s.vorname} ${s.nachname}`.trim(); const first = s.vorname || '';
state.ownerStatuses[fullName] = s.status; const last = s.nachname || '';
const fullName = `${first} ${last}`.trim();
if (fullName) {
state.ownerStatuses[fullName] = s.status;
}
}); });
console.log(`${statuses.length} Eigentümer-Status geladen.`); console.log(`${statuses.length} Eigentümer-Status geladen.`);
@ -1513,9 +1519,11 @@ document.addEventListener('DOMContentLoaded', async () => {
if (ownerLayerName && overlays[ownerLayerName]) { if (ownerLayerName && overlays[ownerLayerName]) {
overlays[ownerLayerName].setStyle(overlays[ownerLayerName].options.style); overlays[ownerLayerName].setStyle(overlays[ownerLayerName].options.style);
} }
} else {
console.warn("API Fehler beim Laden der Status:", response.status);
} }
} catch (err) { } catch (err) {
console.error("Fehler beim Laden der Status:", err); console.error("Netzwerkfehler beim Laden der Status:", err);
} }
} }

View File

@ -115,12 +115,19 @@ app.get('/api/wea/:projekt_id', async (req, res) => {
// Hilfsfunktion zur Auflösung von Projekt-ID oder Name // Hilfsfunktion zur Auflösung von Projekt-ID oder Name
async function resolveProjectId(client, input) { async function resolveProjectId(client, input) {
if (!input) return null;
// Prüfen, ob input eine valide UUID ist // 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; 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; if (uuidRegex.test(input)) return input;
// Sonst in der Projekte-Tabelle nach Name suchen // Normalisierte Suche (Kleinschreibung, Bindestriche zu Unterstrichen)
const res = await client.query('SELECT id FROM geodaten.projekte WHERE name = $1 OR name = $2', [input, input.toLowerCase()]); 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; return res.rows.length > 0 ? res.rows[0].id : null;
} }