FINAL FIX: Switch to pure lowercase SQL without quotes; keeping frontend aliases
Deploy TrassenPlaner / deploy (push) Waiting to run
Details
Deploy TrassenPlaner / deploy (push) Waiting to run
Details
This commit is contained in:
parent
1197919173
commit
6489f42e42
94
server.js
94
server.js
|
|
@ -29,7 +29,7 @@ app.use(express.static(__dirname));
|
||||||
// Helper to run the schema isolation command
|
// Helper to run the schema isolation command
|
||||||
async function setSchema(client) {
|
async function setSchema(client) {
|
||||||
const schema = process.env.DB_SCHEMA || 'wind_projekt_bwscheddebrock';
|
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
|
// Database Initial Setup / Migration Logic Removed
|
||||||
|
|
@ -46,21 +46,21 @@ app.get('/api/owners', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
await setSchema(client);
|
await setSchema(client);
|
||||||
|
|
||||||
// Using exact quoted names to preserve case-sensitivity
|
// Pure lowercase SQL without quotes on identifiers, using aliases for frontend
|
||||||
const query = `
|
const query = `
|
||||||
SELECT
|
select
|
||||||
"id",
|
id,
|
||||||
"Nachname",
|
nachname as "Nachname",
|
||||||
"Vorname",
|
vorname as "Vorname",
|
||||||
"Ort",
|
ort as "Ort",
|
||||||
"Flur",
|
flur as "Flur",
|
||||||
"Flurstueck",
|
flurstueck as "Flurstueck",
|
||||||
"Gemarkung",
|
gemarkung as "Gemarkung",
|
||||||
"status" as "status",
|
status,
|
||||||
"notiz" as "notiz",
|
notiz,
|
||||||
"Str_HNr",
|
str_hnr as "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);
|
||||||
|
|
||||||
|
|
@ -91,11 +91,11 @@ app.get('/api/usage', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
await setSchema(client);
|
await setSchema(client);
|
||||||
const query = `
|
const query = `
|
||||||
SELECT
|
select
|
||||||
"id",
|
id,
|
||||||
"nutzart" as "nutzart",
|
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);
|
||||||
|
|
||||||
|
|
@ -125,11 +125,11 @@ app.get('/api/wea', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
await setSchema(client);
|
await setSchema(client);
|
||||||
const query = `
|
const query = `
|
||||||
SELECT
|
select
|
||||||
"id",
|
id,
|
||||||
"Name",
|
name as "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);
|
||||||
|
|
||||||
|
|
@ -158,10 +158,10 @@ app.get('/api/infrastructure', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
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);
|
||||||
|
|
||||||
|
|
@ -190,11 +190,11 @@ app.get('/api/variants', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
await setSchema(client);
|
await setSchema(client);
|
||||||
const query = `
|
const query = `
|
||||||
SELECT
|
select
|
||||||
"id", "name", "Variante",
|
id, name, variante as "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,19 +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
|
// Save with pure lowercase identifiers
|
||||||
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,10 +266,10 @@ app.patch('/api/owners/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
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' });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue