Redux: alle Active 1 und 0 speichern
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// /pages/api/talas_v5_DB/gisLines/readGisLines.js
|
||||
import mysql from "mysql2/promise";
|
||||
import { store } from "../../../redux/store"; // Redux-Store importieren
|
||||
|
||||
// Erstellen eines Pools von Datenbankverbindungen
|
||||
const pool = mysql.createPool({
|
||||
@@ -18,14 +19,29 @@ export default async function handler(req, res) {
|
||||
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
||||
}
|
||||
|
||||
const query = "SELECT * FROM talas_v5.gis_lines;";
|
||||
// **Hole `idLD`-Werte aus Redux**
|
||||
const state = store.getState();
|
||||
const activeLines = state.lineVisibility.activeLines;
|
||||
const activeIds = Object.keys(activeLines); // Alle `idLD` in Redux
|
||||
|
||||
if (activeIds.length === 0) {
|
||||
return res.status(404).json({ error: "Keine aktiven Geräte in Redux gefunden" });
|
||||
}
|
||||
|
||||
// **SQL-Query mit Filterung**
|
||||
const query = `
|
||||
SELECT *
|
||||
FROM talas_v5.gis_lines
|
||||
WHERE idLD IN (${activeIds.map(() => "?").join(",")});`;
|
||||
|
||||
try {
|
||||
const [results] = await pool.query(query);
|
||||
console.log("🔍 Aktive Linien in Redux:", activeIds);
|
||||
const [results] = await pool.query(query, activeIds); // Verwende aktive `idLD` als Parameter
|
||||
if (results.length > 0) {
|
||||
res.status(200).json(results);
|
||||
console.log("✅ GIS-Linien erfolgreich abgerufen:", results.length, "Linien gefunden.");
|
||||
} else {
|
||||
res.status(404).json({ error: "Gerät nicht gefunden" });
|
||||
res.status(404).json({ error: "Keine passenden Linien gefunden" });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der gis_lines:", error);
|
||||
|
||||
Reference in New Issue
Block a user