fix: Lookup project name by UUID for WEA and Artennachweise
Deploy Standortplaner / deploy (push) Successful in 17s Details

This commit is contained in:
Johannes Baumeister 2026-07-03 09:25:57 +02:00
parent 773475b668
commit bd30641ba5
1 changed files with 27 additions and 6 deletions

View File

@ -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.' }); 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( 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, `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 ST_X(ST_Transform(geom, 4326)) as lng, ST_Y(ST_Transform(geom, 4326)) as lat
FROM geodaten.wea_standorte WHERE projekt_id = $1`, FROM geodaten.wea_standorte WHERE projekt_id = $1 OR projekt_id = $2 OR projekt_id = $3`,
[projekt_id] [projekt_id, resolvedPid, projectName]
); );
log(`Geladen: ${result.rowCount} Anlagen.`); log(`Geladen: ${result.rowCount} Anlagen.`);
res.status(200).json(result.rows); 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; 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 // API zur Flächensicherung von Eigentümern
app.post('/api/sicherung', async (req, res) => { app.post('/api/sicherung', async (req, res) => {
const { nachname, vorname, status, notiz, projekt_id } = req.body; const { nachname, vorname, status, notiz, projekt_id } = req.body;
@ -490,13 +505,19 @@ app.get('/api/layers/artennachweis', async (req, res) => {
if (projectParam) { if (projectParam) {
const projId = await resolveProjectId(client, projectParam); const projId = await resolveProjectId(client, projectParam);
whereClause = `WHERE projekt_id = $1`; const projName = await resolveProjectName(client, projectParam);
params.push(projectParam); // e.g. 'test' or 'BWSamern-Ohne'
if (projId) { whereClause = `WHERE projekt_id = $1`;
whereClause += ` OR projekt_id = $2`; params.push(projectParam); // e.g. 'test' or UUID
if (projId && projId !== projectParam) {
whereClause += ` OR projekt_id = $${params.length + 1}`;
params.push(projId); params.push(projId);
} }
if (projName && projName !== projectParam && projName !== projId) {
whereClause += ` OR projekt_id = $${params.length + 1}`;
params.push(projName);
}
} }
const result = await client.query( const result = await client.query(