Backend: Add stats endpoint for DB connection; UI: Clean up dashboard logic
Deploy Bürgerwind / deploy (push) Successful in 17s Details

This commit is contained in:
Johannes Baumeister 2026-04-30 08:38:21 +02:00
parent af8ed45f4d
commit 7374e98612
8 changed files with 869 additions and 626 deletions

View File

@ -0,0 +1,27 @@
const { Client } = require('pg');
async function check() {
const client = new Client({
host: '87.106.21.21',
port: 5432,
user: 'enwelo_admin',
password: 'WX1t1cgP1qK09',
database: 'enwelo'
});
try {
await client.connect();
const res = await client.query(`
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_schema = 'geodaten' AND table_name = 'flaecheneigentuemer_status';
`);
console.log("Columns in flaecheneigentuemer_status:");
res.rows.forEach(r => console.log(`${r.column_name}: ${r.data_type}`));
} catch (e) {
console.error("Error:", e);
} finally {
await client.end();
}
}
check();

68
backend/test_db_logic.js Normal file
View File

@ -0,0 +1,68 @@
const { Client } = require('pg');
async function testFullLogic() {
const client = new Client({
host: '87.106.21.21',
port: 5432,
user: 'enwelo_admin',
password: 'WX1t1cgP1qK09',
database: 'enwelo'
});
try {
await client.connect();
const vorname = 'Anja';
const nachname = '';
const projekt_name = 'bw_samern-ohne'; // Try the exact DB name or 'BWSamern-Ohne'
console.log(`--- Testing Project Resolution ---`);
const pRes = await client.query(
'SELECT id FROM geodaten.projekte WHERE LOWER(name) = $1 OR LOWER(REPLACE(name, \'-\', \'_\')) = $1',
[projekt_name.toLowerCase().replace(/-/g, '_')]
);
const resolvedPid = pRes.rows.length > 0 ? pRes.rows[0].id : null;
console.log(`Projekt ID für '${projekt_name}':`, resolvedPid);
if (!resolvedPid) return;
console.log(`\n--- Testing ALKIS Search ---`);
const ownerRes = await client.query(
`SELECT "FSK", "VNA", "GNA" FROM geodaten.flaecheneigentuemer_alkis
WHERE ("GNA" = $1 OR ("GNA" IS NULL AND $1 = ''))
AND ("VNA" = $2 OR ("VNA" IS NULL AND $2 = ''))`,
[nachname, vorname]
);
const fsks = ownerRes.rows.map(r => r.FSK);
console.log(`Found ${fsks.length} FSKs for ${vorname} ${nachname}:`, fsks);
if (fsks.length === 0) return;
console.log(`\n--- Testing Zuweisung Check ---`);
let validFsks = [];
for (const fsk of fsks) {
const assignmentRes = await client.query(
`SELECT 1 FROM geodaten.flaecheneigentuemer_alkis_zuweisung WHERE fsk = $1 AND projekt_id = $2`,
[fsk, resolvedPid]
);
console.log(`FSK ${fsk} is assigned to project:`, assignmentRes.rowCount > 0);
if (assignmentRes.rowCount > 0) validFsks.push(fsk);
}
console.log(`\n--- Overall result ---`);
console.log(`If this were the API, it would save ${validFsks.length} statuses.`);
// Also let's check the zuweisung table generally for this project to see how many exist
const allZuw = await client.query(
`SELECT COUNT(*) FROM geodaten.flaecheneigentuemer_alkis_zuweisung WHERE projekt_id = $1`,
[resolvedPid]
);
console.log(`Total FSKs assigned to this project in zuweisung table:`, allZuw.rows[0].count);
} catch (e) {
console.error("Error:", e);
} finally {
await client.end();
}
}
testFullLogic();

View File

@ -0,0 +1,30 @@
const { Client } = require('pg');
async function testInsert() {
const client = new Client({
host: '87.106.21.21',
port: 5432,
user: 'enwelo_admin',
password: 'WX1t1cgP1qK09',
database: 'enwelo'
});
try {
await client.connect();
await client.query('BEGIN');
const res = await client.query(
`INSERT INTO geodaten.flaecheneigentuemer_status (id, fsk, projekt_id, status, datum)
VALUES (gen_random_uuid(), '034212009000090003__', '5bb4e049-85f2-4433-b38e-6a66b81e9f06', 'Gesichert', NOW()) RETURNING *`
);
console.log("Insert success:", res.rows[0]);
await client.query('ROLLBACK');
console.log("Rollback success");
} catch (e) {
console.error("Insert failed:", e);
} finally {
await client.end();
}
}
testInsert();

View File

@ -0,0 +1,39 @@
const { Client } = require('pg');
async function testQuery() {
const client = new Client({
host: '87.106.21.21',
port: 5432,
user: 'enwelo_admin',
password: 'WX1t1cgP1qK09',
database: 'enwelo'
});
try {
await client.connect();
const nachname = '';
const vorname = 'Anja';
console.log(`Querying for GNA='${nachname}' AND VNA='${vorname}'`);
const res1 = await client.query(
`SELECT "FSK" FROM geodaten.flaecheneigentuemer_alkis WHERE "GNA" = $1 AND "VNA" = $2`,
[nachname, vorname]
);
console.log(`Found: ${res1.rowCount} rows.`);
console.log(`Querying for (GNA=$1 OR (GNA IS NULL AND $1='')) AND VNA=$2`);
const res2 = await client.query(
`SELECT "FSK" FROM geodaten.flaecheneigentuemer_alkis
WHERE ("GNA" = $1 OR ("GNA" IS NULL AND $1 = ''))
AND ("VNA" = $2 OR ("VNA" IS NULL AND $2 = ''))`,
[nachname, vorname]
);
console.log(`Found: ${res2.rowCount} rows.`);
} catch (e) {
console.error("Error:", e);
} finally {
await client.end();
}
}
testQuery();

View File

@ -0,0 +1,17 @@
const https = require('https');
https.get('https://bw-samern-ohne.enwelo-serverumgebung.cloud/api/sicherung/bw_samern-ohne', (res) => {
console.log('statusCode:', res.statusCode);
let data = '';
res.on('data', (d) => {
data += d;
});
res.on('end', () => {
console.log(data.substring(0, 500));
});
}).on('error', (e) => {
console.error(e);
});

View File

@ -0,0 +1,27 @@
const { Client } = require('pg');
async function testProject() {
const client = new Client({
host: '87.106.21.21',
port: 5432,
user: 'enwelo_admin',
password: 'WX1t1cgP1qK09',
database: 'enwelo'
});
try {
await client.connect();
const input = 'BWSamern-Ohne';
const normalized = input.toLowerCase().replace(/[-_]/g, '');
const res = await client.query(
'SELECT id FROM geodaten.projekte WHERE LOWER(REPLACE(REPLACE(name, \'-\', \'\'), \'_\', \'\')) = $1',
[normalized]
);
console.log(`Projekt ID für '${input}':`, res.rows.length > 0 ? res.rows[0].id : null);
} catch (e) {
console.error("Error:", e);
} finally {
await client.end();
}
}
testProject();

View File

@ -229,6 +229,41 @@ app.get('/api/sicherung/:projekt_id', async (req, res) => {
}
});
// API für Projekt-Statistiken (Fortschrittsanzeige)
app.get('/api/stats/:projekt_id', async (req, res) => {
const { projekt_id } = req.params;
log(`Lade Statistiken für Projekt: ${projekt_id}`);
const client = await pool.connect();
try {
const resolvedPid = await resolveProjectId(client, projekt_id);
if (!resolvedPid) {
throw new Error(`Projekt '${projekt_id}' konnte nicht gefunden werden.`);
}
// Verwende die vom User vorgeschlagene Logik, aber mit resolvedPid
// Wir gruppieren nach aktueller_status (da dies in der View v_projekt_sicherung so heißt)
const result = await client.query(
`SELECT
aktueller_status as status,
count(*) as anzahl,
ROUND(SUM(ST_Area(geom)) / 10000, 2) as hektar
FROM geodaten.v_projekt_sicherung
WHERE projekt_id = $1
GROUP BY aktueller_status`,
[resolvedPid]
);
log(`Statistiken berechnet: ${result.rows.length} Status-Gruppen.`);
res.json(result.rows);
} catch (e) {
log(`FEHLER beim Laden der Statistiken: ${e.message}`);
res.status(500).json({ error: e.message });
} finally {
client.release();
}
});
// Catch-all route to serve index.html for any other request (optional, good for SPAs)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));

1252
style.css

File diff suppressed because it is too large Load Diff