diff --git a/server.js b/server.js index fb25f97..36836f5 100644 --- a/server.js +++ b/server.js @@ -277,11 +277,14 @@ app.get('/api/wea/:projekt_id', async (req, res) => { return res.status(403).json({ error: 'Keine Berechtigung für dieses Projekt.' }); } + const projectName = await resolveProjectName(client, projekt_id); + const resolvedPid = await resolveProjectId(client, projekt_id); + const result = await client.query( `SELECT wea_nummer as nr, hersteller as hersteller, anlagentyp as type, nabenhoehe as hh, rotordurchmesser as rd, ksf_drehung as ksfAngle, variante as variant, ST_X(ST_Transform(geom, 4326)) as lng, ST_Y(ST_Transform(geom, 4326)) as lat - FROM geodaten.wea_standorte WHERE projekt_id = $1`, - [projekt_id] + FROM geodaten.wea_standorte WHERE projekt_id = $1 OR projekt_id = $2 OR projekt_id = $3`, + [projekt_id, resolvedPid, projectName] ); log(`Geladen: ${result.rowCount} Anlagen.`); res.status(200).json(result.rows); @@ -311,6 +314,18 @@ async function resolveProjectId(client, input) { return res.rows.length > 0 ? res.rows[0].id : null; } +// Hilfsfunktion zur Auflösung des Projekt-Namens anhand der UUID oder des Namens +async function resolveProjectName(client, input) { + if (!input) return null; + + 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)) { + const res = await client.query('SELECT name FROM geodaten.projekte WHERE id = $1', [input]); + return res.rows.length > 0 ? res.rows[0].name : input; + } + return input; +} + // API zur Flächensicherung von Eigentümern app.post('/api/sicherung', async (req, res) => { const { nachname, vorname, status, notiz, projekt_id } = req.body; @@ -490,13 +505,19 @@ app.get('/api/layers/artennachweis', async (req, res) => { if (projectParam) { const projId = await resolveProjectId(client, projectParam); - whereClause = `WHERE projekt_id = $1`; - params.push(projectParam); // e.g. 'test' or 'BWSamern-Ohne' + const projName = await resolveProjectName(client, projectParam); - if (projId) { - whereClause += ` OR projekt_id = $2`; + whereClause = `WHERE projekt_id = $1`; + params.push(projectParam); // e.g. 'test' or UUID + + if (projId && projId !== projectParam) { + whereClause += ` OR projekt_id = $${params.length + 1}`; params.push(projId); } + if (projName && projName !== projectParam && projName !== projId) { + whereClause += ` OR projekt_id = $${params.length + 1}`; + params.push(projName); + } } const result = await client.query(