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