CRITICAL FIX: Restore case-sensitive column naming and double quotes in SQL
Deploy TrassenPlaner / deploy (push) Waiting to run Details

This commit is contained in:
Johannes Baumeister 2026-04-20 09:09:04 +02:00
parent 2dafc94865
commit 1197919173
1 changed files with 32 additions and 31 deletions

View File

@ -46,20 +46,20 @@ app.get('/api/owners', async (req, res) => {
try { try {
await setSchema(client); await setSchema(client);
// Using mapping with aliases to keep the frontend compatible // Using exact quoted names to preserve case-sensitivity
const query = ` const query = `
SELECT SELECT
id, "id",
nachname AS "Nachname", "Nachname",
vorname AS "Vorname", "Vorname",
ort AS "Ort", "Ort",
flur AS "Flur", "Flur",
flurstueck AS "Flurstueck", "Flurstueck",
gemarkung AS "Gemarkung", "Gemarkung",
status, "status" as "status",
notiz, "notiz" as "notiz",
str_hnr AS "Str_HNr", "Str_HNr",
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry ST_AsGeoJSON(ST_Transform("geom", 4326)) as geometry
FROM "eigentuemerdaten" FROM "eigentuemerdaten"
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -92,9 +92,9 @@ app.get('/api/usage', async (req, res) => {
await setSchema(client); await setSchema(client);
const query = ` const query = `
SELECT SELECT
id, "id",
nutzart AS "nutzart", "nutzart" as "nutzart",
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry ST_AsGeoJSON(ST_Transform("geom", 4326)) as geometry
FROM "nutzung" FROM "nutzung"
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -126,9 +126,9 @@ app.get('/api/wea', async (req, res) => {
await setSchema(client); await setSchema(client);
const query = ` const query = `
SELECT SELECT
id, "id",
name AS "Name", "Name",
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry ST_AsGeoJSON(ST_Transform("geom", 4326)) as geometry
FROM "wea" FROM "wea"
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -159,8 +159,8 @@ app.get('/api/infrastructure', async (req, res) => {
await setSchema(client); await setSchema(client);
const query = ` const query = `
SELECT SELECT
id, "id",
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry ST_AsGeoJSON(ST_Transform("geom", 4326)) as geometry
FROM "infrastruktur" FROM "infrastruktur"
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -191,10 +191,10 @@ app.get('/api/variants', async (req, res) => {
await setSchema(client); await setSchema(client);
const query = ` const query = `
SELECT SELECT
id, name, variante AS "Variante", "id", "name", "Variante",
ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry ST_AsGeoJSON(ST_Transform(ST_SetSRID("geom", 25832), 4326)) as geometry
FROM "kabeltrasse" FROM "kabeltrasse"
ORDER BY id DESC ORDER BY "id" DESC
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -233,18 +233,19 @@ app.post('/api/variants', async (req, res) => {
const varianteValue = properties.Variante || (properties.name ? properties.name.replace('Variante ', '') : 'A'); const varianteValue = properties.Variante || (properties.name ? properties.name.replace('Variante ', '') : 'A');
const geoJsonStr = JSON.stringify(geometry); const geoJsonStr = JSON.stringify(geometry);
// Using exact quoted column names for the UPSERT
const upsertQuery = ` const upsertQuery = `
INSERT INTO "kabeltrasse" (geom, name, variante) INSERT INTO "kabeltrasse" ("geom", "name", "Variante")
VALUES ( VALUES (
ST_MakeValid(ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON($1), 4326), 25832)), ST_MakeValid(ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON($1), 4326), 25832)),
$2, $2,
$3 $3
) )
ON CONFLICT (variante) ON CONFLICT ("Variante")
DO UPDATE SET DO UPDATE SET
geom = EXCLUDED.geom, "geom" = EXCLUDED."geom",
name = EXCLUDED.name "name" = EXCLUDED."name"
RETURNING id RETURNING "id"
`; `;
const upsertRes = await client.query(upsertQuery, [geoJsonStr, routeName, varianteValue]); const upsertRes = await client.query(upsertQuery, [geoJsonStr, routeName, varianteValue]);
@ -266,9 +267,9 @@ app.patch('/api/owners/:id', async (req, res) => {
await setSchema(client); await setSchema(client);
const query = ` const query = `
UPDATE "eigentuemerdaten" UPDATE "eigentuemerdaten"
SET status = $1, notiz = $2 SET "status" = $1, "notiz" = $2
WHERE id = $3 WHERE "id" = $3
RETURNING id; RETURNING "id";
`; `;
const result = await client.query(query, [status, notiz, id]); const result = await client.query(query, [status, notiz, id]);
if (result.rowCount === 0) return res.status(404).json({ error: 'Owner not found' }); if (result.rowCount === 0) return res.status(404).json({ error: 'Owner not found' });