FINAL SCHEMA MATCH: Quoted mixed-case columns for QGIS compatibility
Deploy TrassenPlaner / deploy (push) Waiting to run
Details
Deploy TrassenPlaner / deploy (push) Waiting to run
Details
This commit is contained in:
parent
6489f42e42
commit
7753c8b262
87
server.js
87
server.js
|
|
@ -29,7 +29,7 @@ app.use(express.static(__dirname));
|
|||
// Helper to run the schema isolation command
|
||||
async function setSchema(client) {
|
||||
const schema = process.env.DB_SCHEMA || 'wind_projekt_bwscheddebrock';
|
||||
await client.query(`set search_path to ${schema}, public;`);
|
||||
await client.query(`SET search_path TO "${schema}", public;`);
|
||||
}
|
||||
|
||||
// Database Initial Setup / Migration Logic Removed
|
||||
|
|
@ -46,21 +46,23 @@ app.get('/api/owners', async (req, res) => {
|
|||
try {
|
||||
await setSchema(client);
|
||||
|
||||
// Pure lowercase SQL without quotes on identifiers, using aliases for frontend
|
||||
// Strict Case-Sensitivity Mapping based on server structure
|
||||
const query = `
|
||||
select
|
||||
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
|
||||
from eigentuemerdaten
|
||||
nachname AS "Nachname",
|
||||
vorname AS "Vorname",
|
||||
ort AS "Ort",
|
||||
"Flur" AS "Flur",
|
||||
"FlSt" AS "Flurstueck",
|
||||
"Gema" AS "Gemarkung",
|
||||
"PLZ" AS "PLZ",
|
||||
"Land" AS "Land",
|
||||
"AFlaeche" AS "AFlaeche",
|
||||
status as "status",
|
||||
notiz as "notiz",
|
||||
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
|
||||
FROM eigentuemerdaten
|
||||
`;
|
||||
const result = await client.query(query);
|
||||
|
||||
|
|
@ -91,11 +93,11 @@ app.get('/api/usage', async (req, res) => {
|
|||
try {
|
||||
await setSchema(client);
|
||||
const query = `
|
||||
select
|
||||
SELECT
|
||||
id,
|
||||
nutzart,
|
||||
st_asgeojson(st_transform(geom, 4326)) as geometry
|
||||
from nutzung
|
||||
"nutzart" as "nutzart",
|
||||
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
|
||||
FROM nutzung
|
||||
`;
|
||||
const result = await client.query(query);
|
||||
|
||||
|
|
@ -125,11 +127,11 @@ app.get('/api/wea', async (req, res) => {
|
|||
try {
|
||||
await setSchema(client);
|
||||
const query = `
|
||||
select
|
||||
SELECT
|
||||
id,
|
||||
name as "Name",
|
||||
st_asgeojson(st_transform(geom, 4326)) as geometry
|
||||
from wea
|
||||
"Name" AS "Name",
|
||||
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
|
||||
FROM wea
|
||||
`;
|
||||
const result = await client.query(query);
|
||||
|
||||
|
|
@ -158,10 +160,10 @@ app.get('/api/infrastructure', async (req, res) => {
|
|||
try {
|
||||
await setSchema(client);
|
||||
const query = `
|
||||
select
|
||||
SELECT
|
||||
id,
|
||||
st_asgeojson(st_transform(geom, 4326)) as geometry
|
||||
from infrastruktur
|
||||
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
|
||||
FROM infrastruktur
|
||||
`;
|
||||
const result = await client.query(query);
|
||||
|
||||
|
|
@ -190,11 +192,11 @@ app.get('/api/variants', async (req, res) => {
|
|||
try {
|
||||
await setSchema(client);
|
||||
const query = `
|
||||
select
|
||||
id, name, variante as "Variante",
|
||||
st_asgeojson(st_transform(st_setsrid(geom, 25832), 4326)) as geometry
|
||||
from kabeltrasse
|
||||
order by id desc
|
||||
SELECT
|
||||
id, name, "Variante" AS "Variante",
|
||||
ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry
|
||||
FROM kabeltrasse
|
||||
ORDER BY id DESC
|
||||
`;
|
||||
const result = await client.query(query);
|
||||
|
||||
|
|
@ -233,19 +235,18 @@ app.post('/api/variants', async (req, res) => {
|
|||
const varianteValue = properties.Variante || (properties.name ? properties.name.replace('Variante ', '') : 'A');
|
||||
const geoJsonStr = JSON.stringify(geometry);
|
||||
|
||||
// Save with pure lowercase identifiers
|
||||
const upsertQuery = `
|
||||
insert into kabeltrasse (geom, name, variante)
|
||||
values (
|
||||
st_makevalid(st_transform(st_setsrid(st_geomfromgeojson($1), 4326), 25832)),
|
||||
INSERT INTO kabeltrasse (geom, name, "Variante")
|
||||
VALUES (
|
||||
ST_MakeValid(ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON($1), 4326), 25832)),
|
||||
$2,
|
||||
$3
|
||||
)
|
||||
on conflict (variante)
|
||||
do update set
|
||||
geom = excluded.geom,
|
||||
name = excluded.name
|
||||
returning id
|
||||
ON CONFLICT ("Variante")
|
||||
DO UPDATE SET
|
||||
geom = EXCLUDED.geom,
|
||||
name = EXCLUDED.name
|
||||
RETURNING id
|
||||
`;
|
||||
|
||||
const upsertRes = await client.query(upsertQuery, [geoJsonStr, routeName, varianteValue]);
|
||||
|
|
@ -266,10 +267,10 @@ app.patch('/api/owners/:id', async (req, res) => {
|
|||
try {
|
||||
await setSchema(client);
|
||||
const query = `
|
||||
update eigentuemerdaten
|
||||
set status = $1, notiz = $2
|
||||
where id = $3
|
||||
returning id;
|
||||
UPDATE eigentuemerdaten
|
||||
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' });
|
||||
|
|
|
|||
Loading…
Reference in New Issue