server.js aktualisiert
Deploy-TrassenPlaner / deploy (push) Successful in 12s
Details
Deploy-TrassenPlaner / deploy (push) Successful in 12s
Details
This commit is contained in:
parent
b4c7333fa1
commit
b03787b969
20
server.js
20
server.js
|
|
@ -27,7 +27,6 @@ app.use(express.json({ limit: '50mb' }));
|
||||||
app.use(express.static(__dirname));
|
app.use(express.static(__dirname));
|
||||||
|
|
||||||
// Helper to run the schema isolation command
|
// Helper to run the schema isolation command
|
||||||
// This ensures all subsequent queries in this client session use the specified schema
|
|
||||||
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;`);
|
||||||
|
|
@ -40,8 +39,7 @@ const initDBData = async () => {
|
||||||
await setSchema(client);
|
await setSchema(client);
|
||||||
console.log(`Prüfe Datenbank-Schema (Schema: ${process.env.DB_SCHEMA})...`);
|
console.log(`Prüfe Datenbank-Schema (Schema: ${process.env.DB_SCHEMA})...`);
|
||||||
|
|
||||||
// Ensure id_0 is BIGINT
|
// id_0 check removed as requested (column is 'id')
|
||||||
await client.query('ALTER TABLE "Kabeltrasse" ALTER COLUMN id_0 TYPE BIGINT');
|
|
||||||
|
|
||||||
// Enforce SRID 25832 and LineString type
|
// Enforce SRID 25832 and LineString type
|
||||||
try {
|
try {
|
||||||
|
|
@ -59,7 +57,7 @@ const initDBData = async () => {
|
||||||
await client.query(`
|
await client.query(`
|
||||||
DELETE FROM "Kabeltrasse" a
|
DELETE FROM "Kabeltrasse" a
|
||||||
USING "Kabeltrasse" b
|
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); }
|
} 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;
|
const geomObj = typeof geometry === 'string' ? JSON.parse(geometry) : geometry;
|
||||||
return {
|
return {
|
||||||
type: "Feature",
|
type: "Feature",
|
||||||
id: row.id || row.id_0,
|
id: row.id,
|
||||||
geometry: geomObj,
|
geometry: geomObj,
|
||||||
properties: properties
|
properties: properties
|
||||||
};
|
};
|
||||||
|
|
@ -125,8 +123,6 @@ app.get('/api/usage', async (req, res) => {
|
||||||
const client = await pool.connect();
|
const client = await pool.connect();
|
||||||
try {
|
try {
|
||||||
await setSchema(client);
|
await setSchema(client);
|
||||||
const countRes = await client.query('SELECT count(*) FROM "Nutzung"');
|
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
SELECT
|
SELECT
|
||||||
*,
|
*,
|
||||||
|
|
@ -237,14 +233,12 @@ app.get('/api/variants', async (req, res) => {
|
||||||
const client = await pool.connect();
|
const client = await pool.connect();
|
||||||
try {
|
try {
|
||||||
await setSchema(client);
|
await setSchema(client);
|
||||||
const countRes = await client.query('SELECT count(*) FROM "Kabeltrasse"');
|
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
SELECT
|
SELECT
|
||||||
id_0 as id, name, "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_0 DESC
|
ORDER BY id DESC
|
||||||
`;
|
`;
|
||||||
const result = await client.query(query);
|
const result = await client.query(query);
|
||||||
|
|
||||||
|
|
@ -295,11 +289,11 @@ app.post('/api/variants', async (req, res) => {
|
||||||
DO UPDATE SET
|
DO UPDATE SET
|
||||||
geom = EXCLUDED.geom,
|
geom = EXCLUDED.geom,
|
||||||
name = EXCLUDED.name
|
name = EXCLUDED.name
|
||||||
RETURNING id_0
|
RETURNING id
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const upsertRes = await client.query(upsertQuery, [geoJsonStr, routeName, variante]);
|
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 });
|
res.json({ success: true, id: finalId });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue