From 3ce303a00faa9d9cc7e2cf550514d3df2e384cd7 Mon Sep 17 00:00:00 2001 From: Johannes Baumeister Date: Sat, 4 Jul 2026 21:58:56 +0200 Subject: [PATCH] fix: store and retrieve nennleistung (MW) properly in DB and frontend --- db_add_nennleistung.js | 24 ++++++++++++++++++++++++ server.js | 8 ++++---- 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 db_add_nennleistung.js diff --git a/db_add_nennleistung.js b/db_add_nennleistung.js new file mode 100644 index 0000000..b43028c --- /dev/null +++ b/db_add_nennleistung.js @@ -0,0 +1,24 @@ +require('dotenv').config({ override: true }); +const { Pool } = require('pg'); + +const pool = new Pool({ + host: process.env.DB_HOST, + port: process.env.DB_PORT, + database: process.env.DB_NAME, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD +}); + +async function run() { + try { + console.log('Adding nennleistung to wea_standorte...'); + await pool.query('ALTER TABLE geodaten.wea_standorte ADD COLUMN IF NOT EXISTS nennleistung numeric;'); + console.log('Column added successfully.'); + } catch (err) { + console.error('Error adding column:', err); + } finally { + await pool.end(); + } +} + +run(); diff --git a/server.js b/server.js index 0df1436..a4ceb41 100644 --- a/server.js +++ b/server.js @@ -263,9 +263,9 @@ app.post('/api/wea', async (req, res) => { log(`Füge WEA ein: Nr=${t.nr}, Typ=${t.type}, Pos=${t.latlng?.lat},${t.latlng?.lng}`); await client.query( `INSERT INTO ${schema}.wea_standorte - (projekt_id, wea_nummer, hersteller, anlagentyp, nabenhoehe, rotordurchmesser, ksf_drehung, variante, geom) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, ST_Transform(ST_SetSRID(ST_MakePoint($9, $10), 4326), 25832))`, - [targetProject, t.nr, t.hersteller, t.type, t.hh, t.rd, t.ksfAngle, t.variant, t.latlng.lng, t.latlng.lat] + (projekt_id, wea_nummer, hersteller, anlagentyp, nabenhoehe, rotordurchmesser, ksf_drehung, variante, nennleistung, geom) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, ST_Transform(ST_SetSRID(ST_MakePoint($10, $11), 4326), 25832))`, + [targetProject, t.nr, t.hersteller, t.type, t.hh, t.rd, t.ksfAngle, t.variant, t.mw, t.latlng.lng, t.latlng.lat] ); } } @@ -298,7 +298,7 @@ app.get('/api/wea/:projekt_id', async (req, res) => { 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, + `SELECT wea_nummer as nr, hersteller as hersteller, anlagentyp as type, nabenhoehe as hh, rotordurchmesser as rd, ksf_drehung as ksfAngle, variante as variant, nennleistung as mw, ST_X(ST_Transform(geom, 4326)) as lng, ST_Y(ST_Transform(geom, 4326)) as lat FROM geodaten.wea_standorte WHERE projekt_id = $1 OR projekt_id = $2 OR projekt_id = $3`, [projekt_id, resolvedPid, projectName]