server.js aktualisiert
Deploy-TrassenPlaner / deploy (push) Successful in 12s Details

This commit is contained in:
gitea-enwelo-jba 2026-04-19 18:03:10 +00:00
parent b4c7333fa1
commit b03787b969
1 changed files with 7 additions and 13 deletions

View File

@ -27,7 +27,6 @@ app.use(express.json({ limit: '50mb' }));
app.use(express.static(__dirname));
// Helper to run the schema isolation command
// This ensures all subsequent queries in this client session use the specified schema
async function setSchema(client) {
const schema = process.env.DB_SCHEMA || 'wind_projekt_bwscheddebrock';
await client.query(`SET search_path TO "${schema}", public;`);
@ -40,8 +39,7 @@ const initDBData = async () => {
await setSchema(client);
console.log(`Prüfe Datenbank-Schema (Schema: ${process.env.DB_SCHEMA})...`);
// Ensure id_0 is BIGINT
await client.query('ALTER TABLE "Kabeltrasse" ALTER COLUMN id_0 TYPE BIGINT');
// id_0 check removed as requested (column is 'id')
// Enforce SRID 25832 and LineString type
try {
@ -59,7 +57,7 @@ const initDBData = async () => {
await client.query(`
DELETE FROM "Kabeltrasse" a
USING "Kabeltrasse" b
WHERE a.id_0 < b.id_0 AND a."Variante" = b."Variante"
WHERE a.id < b.id AND a."Variante" = b."Variante"
`);
} catch(e) { console.warn("Cleanup warning:", e.message); }
@ -105,7 +103,7 @@ app.get('/api/owners', async (req, res) => {
const geomObj = typeof geometry === 'string' ? JSON.parse(geometry) : geometry;
return {
type: "Feature",
id: row.id || row.id_0,
id: row.id,
geometry: geomObj,
properties: properties
};
@ -125,8 +123,6 @@ app.get('/api/usage', async (req, res) => {
const client = await pool.connect();
try {
await setSchema(client);
const countRes = await client.query('SELECT count(*) FROM "Nutzung"');
const query = `
SELECT
*,
@ -237,14 +233,12 @@ app.get('/api/variants', async (req, res) => {
const client = await pool.connect();
try {
await setSchema(client);
const countRes = await client.query('SELECT count(*) FROM "Kabeltrasse"');
const query = `
SELECT
id_0 as id, name, "Variante",
id, name, "Variante",
ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry
FROM "Kabeltrasse"
ORDER BY id_0 DESC
ORDER BY id DESC
`;
const result = await client.query(query);
@ -295,11 +289,11 @@ app.post('/api/variants', async (req, res) => {
DO UPDATE SET
geom = EXCLUDED.geom,
name = EXCLUDED.name
RETURNING id_0
RETURNING id
`;
const upsertRes = await client.query(upsertQuery, [geoJsonStr, routeName, variante]);
const finalId = upsertRes.rows[0].id_0;
const finalId = upsertRes.rows[0].id;
res.json({ success: true, id: finalId });
} catch (err) {