diff --git a/.env.local b/.env.local
index 6760ecd25..582ebfb9b 100644
--- a/.env.local
+++ b/.env.local
@@ -1,7 +1,24 @@
#.env.local
#je nach dem Mysql Server, ob localhost freigegeben ist oder die IP Adresse des Servers, manchmal die beide und manchmal nur eine
-DB_HOST=10.10.0.30
+#DB_HOST=10.10.0.30
+#DB_USER=root
+#DB_PASSWORD="root#$"
+#DB_NAME=talas_v5
+#DB_PORT=3306
+
+
+#########################
+
+#NEXT_PUBLIC_BASE_URL="http://10.10.0.30/talas5/devices/"
+#NEXT_PUBLIC_SERVER_URL="http://10.10.0.70"
+#NEXT_PUBLIC_PROXY_TARGET="http://10.10.0.30"
+#NEXT_PUBLIC_ONLINE_TILE_LAYER="http://10.10.0.30:3000/mapTiles/{z}/{x}/{y}.png"
+#NEXT_PUBLIC_ONLINE_TILE_LAYER="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
+#########################
+
+
+DB_HOST=10.10.0.70
DB_USER=root
DB_PASSWORD="root#$"
DB_NAME=talas_v5
@@ -11,26 +28,10 @@ DB_PORT=3306
#########################
NEXT_PUBLIC_BASE_URL="http://10.10.0.30/talas5/devices/"
-NEXT_PUBLIC_SERVER_URL="http://10.10.0.30"
-NEXT_PUBLIC_PROXY_TARGET="http://10.10.0.30"
-NEXT_PUBLIC_ONLINE_TILE_LAYER="http://10.10.0.30:3000/mapTiles/{z}/{x}/{y}.png"
-#########################
-
-
-#DB_HOST=10.10.0.70
-#DB_USER=root
-#DB_PASSWORD="root#$"
-#DB_NAME=talas_v5
-#DB_PORT=3306
-
-
-#########################
-
-#NEXT_PUBLIC_BASE_URL="http://10.10.0.70/talas5/devices/"
-#NEXT_PUBLIC_SERVER_URL="http://10.10.0.70"
-#NEXT_PUBLIC_PROXY_TARGET="http://10.10.0.70"
-#NEXT_PUBLIC_ONLINE_TILE_LAYER="http://10.10.0.13:3000/mapTiles/{z}/{x}/{y}.png"
-#NEXT_PUBLIC_ONLINE_TILE_LAYER="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
+NEXT_PUBLIC_SERVER_URL="http://10.10.0.70"
+NEXT_PUBLIC_PROXY_TARGET="http://10.10.0.70"
+NEXT_PUBLIC_ONLINE_TILE_LAYER="http://10.10.0.13:3000/mapTiles/{z}/{x}/{y}.png"
+NEXT_PUBLIC_ONLINE_TILE_LAYER="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
#########################
#DB_HOST=192.168.10.167
diff --git a/hooks/useLineData.js b/hooks/useLineData.js
index 3f6dc0540..be5ebae98 100644
--- a/hooks/useLineData.js
+++ b/hooks/useLineData.js
@@ -89,7 +89,9 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
// Setze die Farbe und Tooltip für jede Linie (für alle Prioritätslevel)
colorsByModule[key] = prioColor;
- newTooltipContents[key] = `
+ // Überprüfe, ob ModulTyp den Text "705-FO" enthält
+ if (statis.ModulTyp && statis.ModulTyp.includes("705-FO")) {
+ newTooltipContents[key] = `
${statis.ModulName || "Unknown"}
@@ -109,6 +111,27 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
${values.schleifenwert ? `Schleifenwert: ${values.schleifenwert}` : ""}
`;
+ } else {
+ newTooltipContents[key] = `
+
+
${statis.ModulName || "Unknown"}
+
+
${statis.ModulTyp || "N/A"}
+
+
Slot: ${statis.Modul || "N/A"}
+
+
Station: ${namesData[matchingLine.idLD] || "N/A"}
+
+
+
+ ${messageDisplay}
+
+
${prioNameDisplay}
+
+
+
+ `;
+ }
}
});
diff --git a/pages/api - Kopie/[...path].js b/pages/api - Kopie/[...path].js
new file mode 100644
index 000000000..b270661b1
--- /dev/null
+++ b/pages/api - Kopie/[...path].js
@@ -0,0 +1,20 @@
+// pages/api/[...path].js
+import { createProxyMiddleware } from "http-proxy-middleware";
+//import { SERVER_URL } from "../config/urls.js";
+//console.log("SERVER_URL:", SERVER_URL); // Debug-Ausgabe
+
+export default createProxyMiddleware({
+ //target: "http://192.168.10.58:3001",
+ // Stationen bekommen
+ //target: "http://10.10.0.13", // Ziel-URL des Proxys // API Aufruf zum mapGisStationsStaticDistrictUrl, mapGisStationsStatusDistrictUrl, mapGisStationsMeasurementsUrl, mapGisSystemStaticUrl und mapDataIconUrl
+ target: `${process.env.NEXT_PUBLIC_SERVER_URL}`, //
+ //target: urls.PROXY_TARGET,
+ //target: "http://localhost:3000", // Ziel-URL des Proxys
+ //target: "http://192.168.10.187:3000", // Ziel-URL des Proxys
+ //target: "http://192.168.10.14",
+ changeOrigin: true,
+ pathRewrite: {
+ "^/api": "/", // Optional: Entfernt /api aus dem Pfad, wenn das Backend dies nicht erfordert
+ },
+ logLevel: "debug", // Setzt das Logging-Level auf "debug" für detaillierte Ausgaben
+});
diff --git a/pages/api - Kopie/get-talasIP.js b/pages/api - Kopie/get-talasIP.js
new file mode 100644
index 000000000..1216fbbb7
--- /dev/null
+++ b/pages/api - Kopie/get-talasIP.js
@@ -0,0 +1,20 @@
+// pages/api/get-talasIP.js
+
+export default function handler(req, res) {
+ // Der x-forwarded-for Header könnte mehrere IP-Adressen enthalten, getrennt durch Kommas
+ let clientIp =
+ req.headers["x-forwarded-for"]?.split(",").map((ip) => ip.trim())[0] ||
+ req.socket.remoteAddress;
+
+ // Entfernen möglicher IPv6 "mapped" IPv4 Adressen
+ if (clientIp?.includes("::ffff:")) {
+ clientIp = clientIp.split("::ffff:")[1];
+ }
+
+ // Nur IPv4 Adressen weitergeben, IPv6 Adressen ausschließen
+ if (clientIp && clientIp.includes(":")) {
+ clientIp = ""; // Dies setzt die IP auf leer, wenn es sich um eine IPv6-Adresse handelt
+ }
+
+ res.status(200).json({ ip: clientIp });
+}
diff --git a/pages/api - Kopie/gis-proxy.js b/pages/api - Kopie/gis-proxy.js
new file mode 100644
index 000000000..b76883298
--- /dev/null
+++ b/pages/api - Kopie/gis-proxy.js
@@ -0,0 +1,34 @@
+// /pages/api/gis-proxy.js
+// Importieren der erforderlichen Module
+import httpProxy from "http-proxy";
+import Cookies from "cookies";
+
+// Erstellen eines Proxy-Servers
+const proxy = httpProxy.createProxyServer();
+
+export default (req, res) => {
+ return new Promise((resolve) => {
+ // CORS-Headers einstellen
+ res.setHeader("Access-Control-Allow-Credentials", true);
+ res.setHeader("Access-Control-Allow-Origin", "*");
+
+ // Cookies initialisieren
+ const cookies = new Cookies(req, res);
+ const targetUrl = `${process.env.NEXT_PUBLIC_SERVER_URL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic`;
+
+ // Proxy-Konfiguration und Event-Listener
+ req.on("data", () => {});
+ req.on("end", () => {
+ proxy.web(req, res, { target: targetUrl, changeOrigin: true, selfHandleResponse: false }, (e) => {
+ if (e) {
+ console.error(e);
+ res.status(500).json({ error: "Proxy-Fehler", e });
+ }
+ resolve();
+ });
+ });
+
+ // Weiterleitung der Headers
+ req.headers.cookie = cookies.get("cookie-name") || "";
+ });
+};
diff --git a/pages/api - Kopie/linesColorApi.js b/pages/api - Kopie/linesColorApi.js
new file mode 100644
index 000000000..57ee59262
--- /dev/null
+++ b/pages/api - Kopie/linesColorApi.js
@@ -0,0 +1,64 @@
+// /pages/api/linesColorApi.js
+// http://10.10.0.13/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict
+//In DB gis_lines idLD und idModul anpassen entsprechend
+
+// /pages/api/linesColorApi.js
+import NextCors from "nextjs-cors";
+
+export default async function handler(req, res) {
+ // Run the cors middleware
+ await NextCors(req, res, {
+ // Options
+ methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
+ origin: "*", // Erlauben Sie alle Ursprünge, oder geben Sie spezifische Ursprünge an
+ optionsSuccessStatus: 200, // Legacy-Browser-Unterstützung für 204
+ });
+
+ const response = {
+ Name: "Liste aller Statis der Linien",
+ Zeitstempel: new Date().toISOString(), // Aktuellen Zeitstempel hinzufügen
+ IdMap: "10",
+ Statis: [
+ /* {
+ IdLD: 50922,
+ Modul: 1,
+ DpName: "KUE01_Ausfall",
+ ModulName: "42 Wippershain Sender",
+ // ModulTyp: "nicht vorhanden",
+ ModulTyp: "KÜ705-FO",
+ Message: "KUEG 01: 42 Wippershain Sender Messwerkausfall kommend",
+ Level: 4,
+ PrioColor: "#FFFF00",
+ PrioName: "system",
+ Value: "10 MOhm",
+ },
+ {
+ IdLD: 25440,
+ Modul: 3,
+ DpName: "KUE03_Ausfall",
+ ModulName: "42 Solz Sender",
+ //ModulTyp: "nicht vorhanden",
+ ModulTyp: "KÜSS V2",
+ Message: "KUEG 03: 42 Solz Sender Messwerkausfall kommend",
+ Level: 4,
+ PrioColor: "#FF0000",
+ PrioName: "system",
+ Value: "10 MOhm",
+ },
+ {
+ IdLD: 25440,
+ Modul: 4,
+ DpName: "KUE04_Ausfall",
+ ModulName: "42/13 Bad Hersfeld Gaswerk",
+ ModulTyp: "Kue705-FO",
+ Message: "KUEG 04: 42/13 Bad Hersfeld Gaswerk Messwerkausfall kommend",
+ Level: 4,
+ PrioColor: "#FF00FF",
+ PrioName: "system",
+ Value: "10 MOhm",
+ }, */
+ ],
+ };
+
+ res.status(200).json(response);
+}
diff --git a/pages/api - Kopie/rights.js b/pages/api - Kopie/rights.js
new file mode 100644
index 000000000..507228147
--- /dev/null
+++ b/pages/api - Kopie/rights.js
@@ -0,0 +1,29 @@
+// pages/api/rights.js
+
+export default function handler(req, res) {
+ const { idMap, idUser } = req.query;
+
+ // Beispielhafte Rechte, die je nach idMap und idUser variieren können
+ const rights = {
+ '10': [
+ { IdRight: 1, Name: "Zugriff auf Dashboard" },
+ { IdRight: 56, Name: "Erweiterte Berechtigungen" }
+ ],
+ '2': [
+ { IdRight: 2, Name: "Zugriff auf Einstellungen" }
+ ],
+ '1': [
+ { IdRight: 10, Name: "Admin-Zugriff" },
+ { IdRight: 11, Name: "Zugriff auf alle Daten" }
+ ]
+ };
+
+ // Prüfung, ob eine gültige idMap und idUser vorhanden sind
+ if (rights[idMap] && idUser === '484') {
+ // Rückgabe der spezifischen Rechte basierend auf der idMap und idUser
+ res.status(200).json({ Rights: rights[idMap] });
+ } else {
+ // Rückgabe leerer Rechte für ungültige idMap oder andere Benutzer
+ res.status(200).json({ Rights: [] });
+ }
+}
diff --git a/pages/api - Kopie/talas5/area.js b/pages/api - Kopie/talas5/area.js
new file mode 100644
index 000000000..9205aa5ca
--- /dev/null
+++ b/pages/api - Kopie/talas5/area.js
@@ -0,0 +1,40 @@
+// pages/api/talas_v5/area.js
+// Lesen von talas_v5 MySQL-Datenbank -> area Tabelle enthält DAUZ Geräte
+// Wenn gebraucht wird, dann nutzen ansonsten löschen
+
+import mysql from "mysql";
+
+const dbConfig = {
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+};
+//console.log("my dbconfig: ", dbConfig);
+export default function handler(req, res) {
+ const connection = mysql.createConnection(dbConfig);
+
+ connection.connect((err) => {
+ if (err) {
+ console.error("Fehler beim Verbinden:", err.stack);
+ res.status(500).json({ error: "Verbindungsfehler zur Datenbank" });
+ return;
+ }
+
+ //console.log("Verbunden als ID", connection.threadId);
+ //Fehler weil, existiertdie Tabelle auf localhost:3000 nicht
+ connection.query("SELECT ..., ..., ..., ... FROM ... WHERE ... = ...", (error, results) => {
+ if (error) {
+ console.error("Fehler beim Abrufen der API", error);
+ res.status(500).json({ error: "Fehler bei der Abfrage" });
+ return;
+ }
+
+ // Wichtig: Senden Sie die Antwort zurück
+ res.status(200).json(results);
+
+ connection.end();
+ });
+ });
+}
diff --git a/pages/api - Kopie/talas5/location_device.js b/pages/api - Kopie/talas5/location_device.js
new file mode 100644
index 000000000..9292690e0
--- /dev/null
+++ b/pages/api - Kopie/talas5/location_device.js
@@ -0,0 +1,42 @@
+// Importieren des mysql2 Pakets
+import mysql from "mysql2";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+// Ein Hilfsfunktion, um Anfragen zu vereinfachen
+function queryDatabase(query, params) {
+ return new Promise((resolve, reject) => {
+ pool.query(query, params, (error, results) => {
+ if (error) {
+ return reject(error);
+ }
+ resolve(results);
+ });
+ });
+}
+
+// API-Handler
+export default async function handler(req, res) {
+ try {
+ // Dein SQL-Query und die Parameter
+ const sql = "SELECT idLD, iddevice, name FROM location_device WHERE iddevice = ?";
+ const params = [160]; // Beispielparameter
+
+ // Ausführen der Datenbankabfrage
+ const results = await queryDatabase(sql, params);
+ res.status(200).json(results);
+ } catch (error) {
+ console.error("Fehler beim Abrufen der API", error);
+ res.status(500).json({ error: "Fehler bei der Abfrage" });
+ }
+}
diff --git a/pages/api - Kopie/talas5/webserviceMap/GisStationsMeasurements.js b/pages/api - Kopie/talas5/webserviceMap/GisStationsMeasurements.js
new file mode 100644
index 000000000..5aba69fc6
--- /dev/null
+++ b/pages/api - Kopie/talas5/webserviceMap/GisStationsMeasurements.js
@@ -0,0 +1,116 @@
+// /pages/api/talas5/webserviceMap/GisStationsMeasurements.js
+const GisStationsMeasurements = {
+ "Name": "Liste aller Messungen der Geraete",
+ "Zeitstempel": "2024-05-31T15:25:32.5047629+02:00",
+ "IdMap": "10",
+ "Statis": [
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 3,
+ "Na": "FBT",
+ "Val": "20.5",
+ "Unit": "°C",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ },
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 10,
+ "Na": "GT",
+ "Val": "nicht ermittelbar",
+ "Unit": "°C",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ },
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 2,
+ "Na": "LT",
+ "Val": "Datenlücke",
+ "Unit": "°C",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ },
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 6,
+ "Na": "RLF",
+ "Val": "100.0",
+ "Unit": "%",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ },
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 11,
+ "Na": "TPT",
+ "Val": "8.3",
+ "Unit": "°C",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ },
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 12,
+ "Na": "TT1",
+ "Val": "---",
+ "Unit": "°C",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ },
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 16,
+ "Na": "WFD",
+ "Val": "0.12",
+ "Unit": "mm",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ },
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 8,
+ "Na": "WGM",
+ "Val": "---",
+ "Unit": "m/s",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ },
+ {
+ "IdLD": 50004,
+ "IdL": 18624,
+ "IdDP": 9,
+ "Na": "WGS",
+ "Val": "---",
+ "Unit": "m/s",
+ "Gr": "GMA",
+ "Area_Name": "Renzenhof (RG)"
+ }
+ ]
+ }
+
+ // Export an async function handler for the API route.
+ export default async function handler(req, res) {
+ // Initialize an empty params object to store query parameters.
+ const params = {
+ idMap: req.query.idMap,
+
+ };
+
+ // Check if the requested ID map and user match certain conditions.
+ if (params.idMap === '10') {
+ // If the conditions are met, return the GisStationsMeasurements object with a 200 status code.
+ res.status(200).json(GisStationsMeasurements);
+ } else {
+ // If not, return a 404 error with the message "Not Found".
+ res.status(404).send('Not Found');
+ }
+ };
\ No newline at end of file
diff --git a/pages/api - Kopie/talas5/webserviceMap/GisStationsStaticDistrict.js b/pages/api - Kopie/talas5/webserviceMap/GisStationsStaticDistrict.js
new file mode 100644
index 000000000..bf302f3d7
--- /dev/null
+++ b/pages/api - Kopie/talas5/webserviceMap/GisStationsStaticDistrict.js
@@ -0,0 +1,281 @@
+// /pages/api/talas5/webserviceMap/GisStationsStaticDistrict.js
+const GisStationsStaticDistrict = {
+ "Name": "Liste aller Geraete einer bestimmten Karte",
+ "Zeitstempel": "2024-05-31T15:26:56.9235766+02:00",
+ "IdMap": "10",
+ "Points": [
+ {
+ "LD_Name": "CPL Bentheim",
+ "IdLD": 50017,
+ "Device": "CPL V3.5 mit 16 Kü",
+ "Link": "cpl.aspx?ver=35&kue=16&id=50017",
+ "Location_Name": "Technikraum",
+ "Location_Short": "BEHE",
+ "IdLocation": 17448,
+ "Area_Name": "Bad-Bentheim",
+ "Area_Short": "BEHE--00",
+ "IdArea": 16418,
+ "X": 51.5728,
+ "Y": 9.00056,
+ "Icon": 20,
+ "System": 1,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Drucker",
+ "IdLD": 50084,
+ "Device": "Basisgerät",
+ "Link": "basis.aspx?ver=1&id=50084",
+ "Location_Name": "Technikraum",
+ "Location_Short": "SLUE",
+ "IdLocation": 17776,
+ "Area_Name": "Schlüchtern II",
+ "Area_Short": "SLUE--00",
+ "IdArea": 14688,
+ "X": 53.2455,
+ "Y": 8.1614,
+ "Icon": 14,
+ "System": 200,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Türkontakt",
+ "IdLD": 50666,
+ "Device": "ECI",
+ "Link": "eci.aspx?ver=1&id=50666",
+ "Location_Name": "Technikraum",
+ "Location_Short": "SLUE",
+ "IdLocation": 17776,
+ "Area_Name": "Schlüchtern II",
+ "Area_Short": "SLUE--00",
+ "IdArea": 14688,
+ "X": 53.2455,
+ "Y": 8.1614,
+ "Icon": 17,
+ "System": 2,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Triptis",
+ "IdLD": 50888,
+ "Device": "CPL 200",
+ "Link": "cpl.aspx?ver=30&kue=16&id=50888",
+ "Location_Name": "Technikraum",
+ "Location_Short": "SLUE",
+ "IdLocation": 17776,
+ "Area_Name": "Schlüchtern II",
+ "Area_Short": "SLUE--00",
+ "IdArea": 14688,
+ "X": 53.2455,
+ "Y": 8.1614,
+ "Icon": 20,
+ "System": 1,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Rodaborn I",
+ "IdLD": 50889,
+ "Device": "cpl.mio V>6",
+ "Link": "cplmio.aspx?ver=1&id=50889",
+ "Location_Name": "Technikraum",
+ "Location_Short": "SLUE",
+ "IdLocation": 17776,
+ "Area_Name": "Schlüchtern II",
+ "Area_Short": "SLUE--00",
+ "IdArea": 14688,
+ "X": 53.2455,
+ "Y": 8.1614,
+ "Icon": 20,
+ "System": 1,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Rodaborn II",
+ "IdLD": 50900,
+ "Device": "cpl.mio V>6",
+ "Link": "cplmio.aspx?ver=1&id=50900",
+ "Location_Name": "Technikraum",
+ "Location_Short": "SLUE",
+ "IdLocation": 17776,
+ "Area_Name": "Schlüchtern II",
+ "Area_Short": "SLUE--00",
+ "IdArea": 14688,
+ "X": 53.2455,
+ "Y": 8.1614,
+ "Icon": 20,
+ "System": 1,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Hermsdorf",
+ "IdLD": 50901,
+ "Device": "CPL V3.5 mit 24 Kü",
+ "Link": "cpl.aspx?ver=35&kue=24&id=50901",
+ "Location_Name": "Technikraum",
+ "Location_Short": "SLUE",
+ "IdLocation": 17776,
+ "Area_Name": "Schlüchtern II",
+ "Area_Short": "SLUE--00",
+ "IdArea": 14688,
+ "X": 53.2455,
+ "Y": 8.1614,
+ "Icon": 20,
+ "System": 1,
+ "Active": 1
+ },
+ {
+ "LD_Name": "GMA Littwin (TEST)",
+ "IdLD": 50004,
+ "Device": "Glättemeldeanlage",
+ "Link": "gma.aspx?ver=1&id=50004",
+ "Location_Name": "RG Relaisraum",
+ "Location_Short": "REZR",
+ "IdLocation": 18624,
+ "Area_Name": "Renzenhof (RG)",
+ "Area_Short": "REZHRG00",
+ "IdArea": 16570,
+ "X": 53.246036,
+ "Y": 8.163293,
+ "Icon": 1,
+ "System": 11,
+ "Active": 0
+ },
+ {
+ "LD_Name": "NRS Testserver",
+ "IdLD": 50005,
+ "Device": "Notruf Server",
+ "Link": "nrs_server.aspx?ver=1&id=50005",
+ "Location_Name": "(EV Ammersricht BZR REL)",
+ "Location_Short": "AMME",
+ "IdLocation": 21118,
+ "Area_Name": "Ammersricht BZR (FGN)",
+ "Area_Short": "AMMER--00",
+ "IdArea": 15958,
+ "X": 52.52726,
+ "Y": 12.165488,
+ "Icon": 19,
+ "System": 8,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Gateway 2",
+ "IdLD": 50007,
+ "Device": "Notruf Server",
+ "Link": "nrs_server.aspx?ver=1&id=50007",
+ "Location_Name": "(EV Ammersricht BZR REL)",
+ "Location_Short": "AMME",
+ "IdLocation": 21118,
+ "Area_Name": "Ammersricht BZR (FGN)",
+ "Area_Short": "AMMER--00",
+ "IdArea": 15958,
+ "X": 52.52726,
+ "Y": 12.165488,
+ "Icon": 19,
+ "System": 8,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Basisgerät mit SNMP MVP",
+ "IdLD": 50669,
+ "Device": "Basisgerät + SNMP",
+ "Link": "basisSNMP.aspx?&ver=1&id=50669",
+ "Location_Name": "Mylinghauserstraße Engelbert",
+ "Location_Short": "G-GEVELSBE-1",
+ "IdLocation": 24012,
+ "Area_Name": "Gevelsberg",
+ "Area_Short": "GMA-GEVELSBE",
+ "IdArea": 20919,
+ "X": 51.316799,
+ "Y": 7.33281,
+ "Icon": 14,
+ "System": 200,
+ "Active": 1
+ },
+ {
+ "LD_Name": "Server 3",
+ "IdLD": 50009,
+ "Device": "Notruf Server",
+ "Link": "nrs_server.aspx?ver=1&id=50009",
+ "Location_Name": "Militärringstraße Militärringstraße",
+ "Location_Short": "G-KÖLN-1",
+ "IdLocation": 24015,
+ "Area_Name": "Köln",
+ "Area_Short": "GMA-KÖLN",
+ "IdArea": 20921,
+ "X": 50.898399,
+ "Y": 6.92278,
+ "Icon": 19,
+ "System": 8,
+ "Active": 0
+ },
+ {
+ "LD_Name": "ICL Test 5",
+ "IdLD": 50054,
+ "Device": "ICL",
+ "Link": "icl.aspx?ver=1&id=50054",
+ "Location_Name": "Recheder Mühlenweg Dortmund-Ems-Kanal",
+ "Location_Short": "G-OLFEN-SE-1",
+ "IdLocation": 24022,
+ "Area_Name": "Olfen-Selm",
+ "Area_Short": "GMA-OLFEN-SE",
+ "IdArea": 20926,
+ "X": 51.702202,
+ "Y": 7.40822,
+ "Icon": 23,
+ "System": 100,
+ "Active": 0
+ },
+ {
+ "LD_Name": "ICL Test 3",
+ "IdLD": 50052,
+ "Device": "ICL",
+ "Link": "icl.aspx?ver=1&id=50052",
+ "Location_Name": "Weidenstraße Hestenberg",
+ "Location_Short": "G-PLETTENB-1",
+ "IdLocation": 24024,
+ "Area_Name": "Plettenberg",
+ "Area_Short": "GMA-PLETTENB",
+ "IdArea": 20928,
+ "X": 51.224098,
+ "Y": 7.86969,
+ "Icon": 23,
+ "System": 100,
+ "Active": 0
+ },
+ {
+ "LD_Name": "Test Februar Kai",
+ "IdLD": 50912,
+ "Device": "Dauerzählstelle DZ",
+ "Link": "dauz.aspx?ver=1&id=50912",
+ "Location_Name": "In der Hoffnung Kiesberg - BG Ost",
+ "Location_Short": "G-WUPPERTA-4",
+ "IdLocation": 24039,
+ "Area_Name": "Wuppertal",
+ "Area_Short": "GMA-WUPPERTA",
+ "IdArea": 20937,
+ "X": 51.238899,
+ "Y": 7.12715,
+ "Icon": 14,
+ "System": 110,
+ "Active": 1
+ }
+ ]
+ }
+
+ // Export an async function handler for the API route.
+ export default async function handler(req, res) {
+ // Initialize an empty params object to store query parameters.
+ const params = {
+ idMap: req.query.idMap,
+ idUser: req.query.idUser
+ };
+
+ // Check if the requested ID map and user match certain conditions.
+ if (params.idMap === '10' && params.idUser === '484') {
+ // If the conditions are met, return the GisStationsStaticDistrict object with a 200 status code.
+ res.status(200).json(GisStationsStaticDistrict);
+ } else {
+ // If not, return a 404 error with the message "Not Found".
+ res.status(404).send('Not Found');
+ }
+ };
\ No newline at end of file
diff --git a/pages/api - Kopie/talas5/webserviceMap/GisStationsStatusDistrict.js b/pages/api - Kopie/talas5/webserviceMap/GisStationsStatusDistrict.js
new file mode 100644
index 000000000..ae7c25bde
--- /dev/null
+++ b/pages/api - Kopie/talas5/webserviceMap/GisStationsStatusDistrict.js
@@ -0,0 +1,84 @@
+// /pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Verbindungspools anstelle einer einzelnen Verbindung
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ const { idMap, idUser } = req.query;
+
+ if (!idMap || !idUser) {
+ return res.status(400).json({ error: "idMap and idUser are required" });
+ }
+
+ try {
+ let onlySystem = -1;
+ let districtCounter = 0;
+
+ // Get onlySystem
+ const [mapResult] = await pool.query("SELECT idsystem_typ FROM maps WHERE id = ?", [idMap]);
+ if (mapResult.length > 0) {
+ onlySystem = mapResult[0].idsystem_typ ?? -1;
+ }
+
+ // Get districtCounter
+ if (idUser > 0) {
+ const [userLayerResult] = await pool.query("SELECT count(*) as count FROM user_User_layer1 WHERE iduser = ?", [idUser]);
+ districtCounter = userLayerResult[0].count;
+ }
+
+ // Building the query
+ let query = `
+ SELECT ld.idLD, dc.message, p.level, p.name, p.color, ld.idDevice, de.isService, dc.idIcon
+ FROM location as l
+ LEFT JOIN location_coordinates AS co ON l.idLocation = co.idLocation and co.idMaps = ?
+ LEFT JOIN location_device AS ld ON ld.idLocation = l.idLocation
+ LEFT JOIN datapoint as d ON d.idLD = ld.idLD
+ LEFT JOIN datapoint_conditions AS dc ON dc.idcondition = d.last_message_condition
+ LEFT JOIN prio AS p ON p.idPrio = dc.idprio
+ LEFT JOIN devices AS de ON de.idDevice = ld.idDevice
+ LEFT JOIN area as a on a.idArea = l.idArea
+ WHERE p.level < 100 AND co.X > 0
+ `;
+
+ const queryParams = [idMap];
+ if (districtCounter > 0) {
+ query += ` AND a.iddistrict IN (SELECT iddistrict FROM user_user_layer1 WHERE iduser = ?)`;
+ queryParams.push(idUser);
+ }
+ if (onlySystem >= 0) {
+ query += ` AND de.idsystem_typ = ?`;
+ queryParams.push(onlySystem);
+ }
+ query += ` ORDER BY p.level desc`;
+
+ const [results] = await pool.query(query, queryParams);
+
+ const mpss = {
+ IdMap: idMap.toString(),
+ Statis: results.map((row) => ({
+ IdLD: row.idLD ?? -1,
+ Le: row.level ?? -1,
+ Me: row.message ?? "?",
+ Na: row.name ?? "?",
+ Co: row.color ?? "#ffffff",
+ Feld: row.idDevice ?? -1,
+ Icon: row.idIcon ?? 0,
+ })),
+ };
+
+ res.status(200).json(mpss);
+ } catch (error) {
+ console.error("Fehler beim Laden der Daten:", error);
+ res.status(500).json({ error: "Interner Serverfehler" });
+ }
+}
diff --git a/pages/api - Kopie/talas5/webserviceMap/GisSystemStatic.js b/pages/api - Kopie/talas5/webserviceMap/GisSystemStatic.js
new file mode 100644
index 000000000..b2fb56635
--- /dev/null
+++ b/pages/api - Kopie/talas5/webserviceMap/GisSystemStatic.js
@@ -0,0 +1,273 @@
+// /pages/api/webServiceMap.js
+const gisSystemStatic = {
+ "Name": "Liste aller angezeigten Systeme",
+ "Zeitstempel": "2024-05-31T15:08:49.8599542+02:00",
+ "IdMap": "10",
+ "Systems": [
+ {
+ "IdSystem": 1,
+ "Name": "TALAS",
+ "Longname": "Talas Meldestationen",
+ "Allow": 1,
+ "Icon": 1
+ },
+ {
+ "IdSystem": 2,
+ "Name": "ECI",
+ "Longname": "ECI Geräte",
+ "Allow": 1,
+ "Icon": 2
+ },
+ {
+ "IdSystem": 5,
+ "Name": "GSM Modem",
+ "Longname": "LR77 GSM Modems",
+ "Allow": 1,
+ "Icon": 5
+ },
+ {
+ "IdSystem": 6,
+ "Name": "Cisco Router",
+ "Longname": "Cisco Router",
+ "Allow": 1,
+ "Icon": 6
+ },
+ {
+ "IdSystem": 7,
+ "Name": "WAGO",
+ "Longname": "WAGO I/O Systeme",
+ "Allow": 1,
+ "Icon": 7
+ },
+ {
+ "IdSystem": 8,
+ "Name": "Siemens",
+ "Longname": "Siemens Notrufsystem",
+ "Allow": 0,
+ "Icon": 8
+ },
+ {
+ "IdSystem": 9,
+ "Name": "OTDR",
+ "Longname": "Glasfaserüberwachung OTU",
+ "Allow": 0,
+ "Icon": 9
+ },
+ {
+ "IdSystem": 10,
+ "Name": "WDM",
+ "Longname": " Wavelength Division Multiplexing",
+ "Allow": 0,
+ "Icon": 10
+ },
+ {
+ "IdSystem": 11,
+ "Name": "GMA",
+ "Longname": "Glättemeldeanlagen",
+ "Allow": 1,
+ "Icon": 11
+ },
+ {
+ "IdSystem": 13,
+ "Name": "Messstellen",
+ "Longname": "Messstellen",
+ "Allow": 0,
+ "Icon": 13
+ },
+ {
+ "IdSystem": 100,
+ "Name": "TALAS ICL",
+ "Longname": "Talas ICL Unterstationen",
+ "Allow": 1,
+ "Icon": 100
+ },
+ {
+ "IdSystem": 110,
+ "Name": "DAUZ",
+ "Longname": "Dauerzählstellen",
+ "Allow": 1,
+ "Icon": 110
+ },
+ {
+ "IdSystem": 111,
+ "Name": "SMS-Funkmodem",
+ "Longname": "SMS-Funkmodem",
+ "Allow": 0,
+ "Icon": 111
+ },
+ {
+ "IdSystem": 200,
+ "Name": "Sonstige",
+ "Longname": "Sonstige",
+ "Allow": 1,
+ "Icon": 200
+ }
+ ],
+ "Rights": [
+ {
+ "IdRight": 1
+ },
+ {
+ "IdRight": 2
+ },
+ {
+ "IdRight": 3
+ },
+ {
+ "IdRight": 5
+ },
+ {
+ "IdRight": 6
+ },
+ {
+ "IdRight": 7
+ },
+ {
+ "IdRight": 8
+ },
+ {
+ "IdRight": 10
+ },
+ {
+ "IdRight": 11
+ },
+ {
+ "IdRight": 12
+ },
+ {
+ "IdRight": 20
+ },
+ {
+ "IdRight": 22
+ },
+ {
+ "IdRight": 23
+ },
+ {
+ "IdRight": 25
+ },
+ {
+ "IdRight": 30
+ },
+ {
+ "IdRight": 40
+ },
+ {
+ "IdRight": 41
+ },
+ {
+ "IdRight": 42
+ },
+ {
+ "IdRight": 43
+ },
+ {
+ "IdRight": 44
+ },
+ {
+ "IdRight": 45
+ },
+ {
+ "IdRight": 46
+ },
+ {
+ "IdRight": 47
+ },
+ {
+ "IdRight": 48
+ },
+ {
+ "IdRight": 49
+ },
+ {
+ "IdRight": 50
+ },
+ {
+ "IdRight": 51
+ },
+ {
+ "IdRight": 52
+ },
+ {
+ "IdRight": 55
+ },
+ {
+ "IdRight": 56
+ },
+ {
+ "IdRight": 60
+ },
+ {
+ "IdRight": 61
+ },
+ {
+ "IdRight": 62
+ },
+ {
+ "IdRight": 63
+ },
+ {
+ "IdRight": 64
+ },
+ {
+ "IdRight": 65
+ },
+ {
+ "IdRight": 68
+ },
+ {
+ "IdRight": 69
+ },
+ {
+ "IdRight": 70
+ },
+ {
+ "IdRight": 71
+ },
+ {
+ "IdRight": 72
+ },
+ {
+ "IdRight": 73
+ },
+ {
+ "IdRight": 79
+ },
+ {
+ "IdRight": 80
+ },
+ {
+ "IdRight": 90
+ },
+ {
+ "IdRight": 93
+ },
+ {
+ "IdRight": 94
+ },
+ {
+ "IdRight": 95
+ },
+ {
+ "IdRight": 96
+ }
+ ]
+}
+
+// Export an async function handler for the API route.
+export default async function handler(req, res) {
+ // Initialize an empty params object to store query parameters.
+ const params = {
+ idMap: req.query.idMap,
+ idUser: req.query.idUser
+ };
+
+ // Check if the requested ID map and user match certain conditions.
+ if (params.idMap === '10' && params.idUser === '484') {
+ // If the conditions are met, return the gisSystemStatic object with a 200 status code.
+ res.status(200).json(gisSystemStatic);
+ } else {
+ // If not, return a 404 error with the message "Not Found".
+ res.status(404).send('Not Found');
+ }
+};
\ No newline at end of file
diff --git a/pages/api - Kopie/talas5/webserviceMap/gisStationsMeasurementsSQL.js b/pages/api - Kopie/talas5/webserviceMap/gisStationsMeasurementsSQL.js
new file mode 100644
index 000000000..90c535086
--- /dev/null
+++ b/pages/api - Kopie/talas5/webserviceMap/gisStationsMeasurementsSQL.js
@@ -0,0 +1,74 @@
+// /pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
+import mysql from "mysql2";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+pool.on("connection", function (connection) {
+ console.log("Database connected successfully.");
+});
+
+pool.on("error", function (err) {
+ console.error("Fehler beim Verbinden:", err);
+});
+
+export default function handler(req, res) {
+ const idMap = req.query.idMap;
+ if (req.method !== "GET") {
+ return res.status(405).json({ error: "Nur GET Methode erlaubt" });
+ }
+
+ const sqlQuery = `
+ SELECT
+ ld.idLD,
+ dp.idDP,
+ dp.name AS Na,
+ dp.value AS Val,
+ dp.unit AS Unit,
+ mg.name AS Gr,
+ ld.idLocation,
+ area.Name AS Area_Name
+ FROM location_device as ld
+ LEFT JOIN location_coordinates AS co ON ld.idLocation = co.idLocation and co.idMaps = ?
+ LEFT JOIN devices AS de ON de.idDevice = ld.idDevice
+ LEFT JOIN datapoint AS dp ON ld.idLD = dp.idLD
+ LEFT JOIN message_group AS mg ON dp.idmessage_group = mg.idmessage_group
+ LEFT JOIN location AS loc ON ld.idLocation = loc.idLocation
+ LEFT JOIN area AS area ON loc.idArea = area.idArea
+ WHERE co.X > 0 AND dp.idmessage_group>0 AND length(dp.unit)> 0 AND length(dp.value)> 0
+ `;
+
+ pool.query(sqlQuery, [idMap], (error, results) => {
+ if (error) {
+ console.error("Fehler beim Abrufen der gis_lines:", error);
+ return res.status(500).json({ error: "Fehler beim Abrufen der gis_lines" });
+ }
+
+ const response = {
+ Name: "Liste aller Messungen der Geraete",
+ Zeitstempel: new Date().toISOString(),
+ IdMap: idMap,
+ Statis: results.map((row) => ({
+ IdLD: row.idLD,
+ IdDP: row.idDP,
+ Na: row.Na,
+ Val: row.Val,
+ Unit: row.Unit,
+ Gr: row.Gr,
+ IdLocation: row.idLocation,
+ Area_Name: row.Area_Name,
+ })),
+ };
+
+ res.json(response);
+ });
+}
diff --git a/pages/api - Kopie/talas_v5_DB/gisLines/readGisLines.js b/pages/api - Kopie/talas_v5_DB/gisLines/readGisLines.js
new file mode 100644
index 000000000..d734ed011
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/gisLines/readGisLines.js
@@ -0,0 +1,34 @@
+// /pages/api/talas_v5_DB/gisLines/readGisLines.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "GET") {
+ return res.status(405).json({ error: "Nur GET Methode erlaubt" });
+ }
+
+ const query = "SELECT * FROM talas_v5.gis_lines;";
+
+ try {
+ const [results] = await pool.query(query);
+ if (results.length > 0) {
+ res.status(200).json(results);
+ } else {
+ res.status(404).json({ error: "Gerät nicht gefunden" });
+ }
+ } catch (error) {
+ console.error("Fehler beim Abrufen der gis_lines:", error);
+ res.status(500).json({ error: "Fehler beim Abrufen der gis_lines" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/gisLines/updateLineCoordinates.js b/pages/api - Kopie/talas_v5_DB/gisLines/updateLineCoordinates.js
new file mode 100644
index 000000000..4271160a0
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/gisLines/updateLineCoordinates.js
@@ -0,0 +1,58 @@
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "POST") {
+ return res.status(405).json({ error: "Nur POST Methode erlaubt" });
+ }
+
+ const { idLD, idModul, newCoordinates } = req.body;
+ if (!idLD || !idModul || !newCoordinates) {
+ return res.status(400).json({ error: "Fehlende Daten" });
+ }
+
+ const newLineString = `LINESTRING(${newCoordinates.map((coord) => `${coord[0]} ${coord[1]}`).join(",")})`;
+
+ const query = "UPDATE talas_v5.gis_lines SET points = ST_GeomFromText(?) WHERE idLD = ? AND idModul = ?;";
+
+ let connection;
+
+ try {
+ // Hole eine Verbindung aus dem Pool
+ connection = await pool.getConnection();
+
+ // Beginne eine Transaktion
+ await connection.beginTransaction();
+
+ // Führe die Abfrage aus
+ const [results] = await connection.query(query, [newLineString, idLD, idModul]);
+
+ // Commit der Transaktion
+ await connection.commit();
+
+ console.log("Transaction Complete.");
+ res.status(200).json({
+ success: "Updated successfully.",
+ affectedRows: results.affectedRows,
+ });
+ } catch (error) {
+ // Rollback im Falle eines Fehlers
+ if (connection) await connection.rollback();
+ console.error("Fehler beim Aktualisieren der gis_lines:", error);
+ res.status(500).json({ error: "Fehler beim Aktualisieren der gis_lines" });
+ } finally {
+ // Stelle sicher, dass die Verbindung zurückgegeben wird
+ if (connection) connection.release();
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/locationDevice/getDeviceId.js b/pages/api - Kopie/talas_v5_DB/locationDevice/getDeviceId.js
new file mode 100644
index 000000000..8b2326316
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/locationDevice/getDeviceId.js
@@ -0,0 +1,41 @@
+// API in /api/talas_v5_DB/locationDevice/getDeviceId.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "GET") {
+ return res.status(405).json({ error: "Nur GET Methode erlaubt" });
+ }
+
+ const { deviceName } = req.query;
+
+ if (!deviceName) {
+ return res.status(400).json({ error: "deviceName ist erforderlich" });
+ }
+
+ const query = "SELECT idLD FROM location_device WHERE name = ?";
+
+ try {
+ // Ausführen der Abfrage mit dem Pool
+ const [results] = await pool.query(query, [deviceName]);
+ if (results.length > 0) {
+ res.status(200).json({ idLD: results[0].idLD });
+ } else {
+ res.status(404).json({ error: "Gerät nicht gefunden" });
+ }
+ } catch (error) {
+ console.error("Fehler beim Abrufen der Geräte-ID:", error);
+ res.status(500).json({ error: "Fehler beim Abrufen der Geräte-ID" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/locationDevice/locationDeviceNameById.js b/pages/api - Kopie/talas_v5_DB/locationDevice/locationDeviceNameById.js
new file mode 100644
index 000000000..575541547
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/locationDevice/locationDeviceNameById.js
@@ -0,0 +1,40 @@
+// API in /api/talas_v5_DB/locationDevice/locationDeviceNameById.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "GET") {
+ return res.status(405).json({ error: "Nur GET Methode erlaubt" });
+ }
+
+ const { idLD } = req.query;
+
+ if (!idLD) {
+ return res.status(400).json({ error: "idLD ist erforderlich" });
+ }
+
+ try {
+ const query = "SELECT name FROM location_device WHERE idLD = ?";
+ const [results] = await pool.query(query, [idLD]);
+
+ if (results.length > 0) {
+ res.status(200).json({ name: results[0].name });
+ } else {
+ res.status(404).json({ error: "Gerät nicht gefunden", idLD });
+ }
+ } catch (error) {
+ console.error("Fehler beim Abrufen des Gerätenamens:", error);
+ res.status(500).json({ error: "Fehler beim Abrufen des Gerätenamens" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/locationDevice/locationDevices.js b/pages/api - Kopie/talas_v5_DB/locationDevice/locationDevices.js
new file mode 100644
index 000000000..082dc2929
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/locationDevice/locationDevices.js
@@ -0,0 +1,32 @@
+// API in /api/talas_v5_DB/locationDevice/locationDevices.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "GET") {
+ return res.status(405).json({ error: "Nur GET Methode erlaubt" });
+ }
+
+ const query = "SELECT * FROM location_device WHERE iddevice = 160";
+
+ try {
+ // Ausführen der Abfrage mit dem Verbindungspool
+ const [results] = await pool.query(query);
+
+ res.status(200).json(results);
+ } catch (error) {
+ console.error("Fehler beim Abrufen der Geräteinformationen:", error);
+ res.status(500).json({ error: "Fehler beim Abrufen der Geräteinformationen" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/poiTyp/readPoiTyp.js b/pages/api - Kopie/talas_v5_DB/poiTyp/readPoiTyp.js
new file mode 100644
index 000000000..baff8f83d
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/poiTyp/readPoiTyp.js
@@ -0,0 +1,37 @@
+// pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "GET") {
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+
+ const query = "SELECT * FROM poityp";
+
+ try {
+ // Ausführen der Abfrage mit dem Verbindungspool
+ const [results] = await pool.query(query);
+
+ if (results.length === 0) {
+ return res.status(404).json({ message: "Keine Einträge gefunden" });
+ }
+
+ res.status(200).json(results);
+ } catch (error) {
+ console.error("Fehler beim Abfragen der Datenbank:", error);
+ res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/pois/addLocation.js b/pages/api - Kopie/talas_v5_DB/pois/addLocation.js
new file mode 100644
index 000000000..864835647
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/pois/addLocation.js
@@ -0,0 +1,37 @@
+// pages/api/addLocation.js
+import mysql from "mysql";
+
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ connectionLimit: 10, // Maximale Anzahl gleichzeitiger Verbindungen
+});
+
+export default function handler(req, res) {
+ if (req.method === "POST") {
+ const { name, poiTypeId, latitude, longitude, idLD } = req.body;
+ console.log("Received data:", req.body); // Überprüfen der empfangenen Daten
+
+ const query = "INSERT INTO poi (description, idPoiTyp, position, idLD) VALUES (?, ?, ST_GeomFromText(?),?)";
+ const point = `POINT(${longitude} ${latitude})`;
+ const values = [name, poiTypeId, point, idLD];
+
+ // Verwende den Pool, um eine Verbindung zu bekommen und die Query auszuführen
+ pool.query(query, values, (error, results) => {
+ if (error) {
+ console.error("Fehler beim Einfügen des Standorts:", error);
+ return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
+ }
+ res.status(200).json({
+ id: results.insertId,
+ message: "Standort erfolgreich hinzugefügt",
+ });
+ });
+ } else {
+ res.setHeader("Allow", ["POST"]);
+ res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/pois/deletePoi.js b/pages/api - Kopie/talas_v5_DB/pois/deletePoi.js
new file mode 100644
index 000000000..e9132bd6b
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/pois/deletePoi.js
@@ -0,0 +1,42 @@
+// pages/api/talas_v5_DB/pois/deletePoi.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "DELETE") {
+ return res.status(405).json({ error: "Nur DELETE Methode erlaubt" });
+ }
+
+ const { id } = req.query; // ID aus der Anfrage holen
+
+ if (!id) {
+ return res.status(400).json({ error: "POI ID ist erforderlich" });
+ }
+
+ const query = "DELETE FROM poi WHERE idPoi = ?";
+
+ try {
+ // Ausführen der Abfrage mit dem Verbindungspool
+ const [results] = await pool.query(query, [id]);
+
+ if (results.affectedRows > 0) {
+ res.status(200).json({ message: "POI erfolgreich gelöscht" });
+ } else {
+ res.status(404).json({ error: "POI nicht gefunden" });
+ }
+ } catch (error) {
+ console.error("Fehler beim Löschen des POI 3:", error);
+ res.status(500).json({ error: "Fehler beim Löschen des POI" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/pois/getPoiById.js b/pages/api - Kopie/talas_v5_DB/pois/getPoiById.js
new file mode 100644
index 000000000..3bd2f1023
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/pois/getPoiById.js
@@ -0,0 +1,43 @@
+// pages/api/talas_v5_DB/pois/getPoiById.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "GET") {
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+
+ const { idPoi } = req.query;
+
+ if (!idPoi) {
+ return res.status(400).json({ error: "idPoi ist erforderlich" });
+ }
+
+ const query = "SELECT description FROM poi WHERE idPoi = ?";
+
+ try {
+ // Ausführen der Abfrage mit dem Verbindungspool
+ const [results] = await pool.query(query, [idPoi]);
+
+ if (results.length === 0) {
+ return res.status(404).json({ error: "POI nicht gefunden" });
+ }
+
+ res.status(200).json(results[0]);
+ } catch (error) {
+ console.error("Fehler bei der Abfrage:", error);
+ res.status(500).json({ error: "Fehler bei der Abfrage" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/pois/poi-icons.js b/pages/api - Kopie/talas_v5_DB/pois/poi-icons.js
new file mode 100644
index 000000000..407704538
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/pois/poi-icons.js
@@ -0,0 +1,36 @@
+// pages/api/talas_v5_DB/pois/poi-icons.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "GET") {
+ return res.status(405).json({ error: "Nur GET Methode erlaubt" });
+ }
+
+ const query = `
+ SELECT p.idPoi, i.path
+ FROM poi p
+ JOIN poiTyp pt ON p.idPoiTyp = pt.idPoiTyp
+ JOIN poiicons i ON pt.icon = i.idpoiicons;
+ `;
+
+ try {
+ // Ausführen der Abfrage mit dem Verbindungspool
+ const [results] = await pool.query(query);
+ res.status(200).json(results);
+ } catch (error) {
+ console.error("Fehler beim Abrufen der Icons:", error);
+ res.status(500).json({ error: "Fehler beim Abrufen der Icons" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/pois/readLocations.js b/pages/api - Kopie/talas_v5_DB/pois/readLocations.js
new file mode 100644
index 000000000..308de78af
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/pois/readLocations.js
@@ -0,0 +1,32 @@
+// pages/api/talas_v5_DB/pois/readLocations.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ const query = `
+ SELECT idPoi, description, idPoiTyp, idLD, ST_AsText(position) AS position
+ FROM poi
+ `;
+
+ try {
+ // Ausführen der Abfrage mit dem Verbindungspool
+ const [results] = await pool.query(query);
+
+ // Senden der Antwort zurück
+ res.status(200).json(results);
+ } catch (error) {
+ console.error("Fehler beim Abrufen der API:", error);
+ res.status(500).json({ error: "Fehler bei der Abfrage" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/pois/updateLocation.js b/pages/api - Kopie/talas_v5_DB/pois/updateLocation.js
new file mode 100644
index 000000000..ee61070f2
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/pois/updateLocation.js
@@ -0,0 +1,82 @@
+// pages/api/talas_v5_DB/pois/updateLocation.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ charset: "utf8mb4",
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "POST") {
+ res.setHeader("Allow", ["POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+
+ const { id, latitude, longitude } = req.body;
+
+ if (!id || latitude === undefined || longitude === undefined) {
+ return res.status(400).json({ error: "id, latitude, und longitude sind erforderlich" });
+ }
+
+ const query = "UPDATE poi SET position = POINT(?, ?) WHERE idPoi = ?";
+
+ try {
+ const [result] = await pool.query(query, [longitude, latitude, id]);
+
+ if (result.affectedRows > 0) {
+ res.status(200).json({ success: true });
+ } else {
+ res.status(404).json({ error: "POI nicht gefunden" });
+ }
+ } catch (error) {
+ console.error("Fehler beim Aktualisieren der Position:", error);
+ res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
+ }
+}
+
+/* import mysql from "mysql";
+import util from "util";
+
+const dbConfig = {
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ charset: "utf8mb4",
+};
+
+export default async function handler(req, res) {
+ if (req.method !== "POST") {
+ res.setHeader("Allow", ["POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+
+ const { id, latitude, longitude } = req.body;
+
+ const connection = mysql.createConnection(dbConfig);
+ // Promisify the query method
+ const query = util.promisify(connection.query).bind(connection);
+
+ try {
+ await query("UPDATE poi SET position = POINT(?, ?) WHERE idPoi = ?", [
+ longitude,
+ latitude,
+ id,
+ ]);
+ res.status(200).json({ success: true });
+ } catch (error) {
+ console.error(error);
+ res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
+ } finally {
+ connection.end();
+ }
+} */
diff --git a/pages/api - Kopie/talas_v5_DB/pois/updatePoi.js b/pages/api - Kopie/talas_v5_DB/pois/updatePoi.js
new file mode 100644
index 000000000..bc3356a2f
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/pois/updatePoi.js
@@ -0,0 +1,45 @@
+// pages/api/talas_v5_DB/pois/updatePoi.js
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "POST") {
+ return res.status(405).json({ error: "Nur POST Methode erlaubt" });
+ }
+
+ const { idPoi, description, idPoiTyp, idLD } = req.body;
+
+ if (!idPoi) {
+ return res.status(400).json({ error: "POI ID ist erforderlich" });
+ }
+
+ const query = `
+ UPDATE talas_v5.poi
+ SET description = ?, idPoiTyp = ?, idLD = ?
+ WHERE idPoi = ?
+ `;
+
+ try {
+ const [results] = await pool.query(query, [description, idPoiTyp, idLD, idPoi]);
+
+ if (results.affectedRows > 0) {
+ res.status(200).json({ message: "POI erfolgreich aktualisiert" });
+ } else {
+ res.status(404).json({ error: "POI nicht gefunden" });
+ }
+ } catch (error) {
+ console.error("Fehler beim Aktualisieren des POI:", error);
+ res.status(500).json({ error: "Fehler beim Aktualisieren des POI" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/priorityConfig.js b/pages/api - Kopie/talas_v5_DB/priorityConfig.js
new file mode 100644
index 000000000..719007020
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/priorityConfig.js
@@ -0,0 +1,31 @@
+// pages/api/talas_v5_DB/priorityConfig.js
+// in tals5 http://10.10.0.13/talas5/Management/PriorityConfig.aspx beinhaltet die Tabelle prio die Prioritäten der Meldungen (Level 1-4) oder (0-4) je nachdem DB-Design
+// das ist die API, die die Prioritäten zurückgibt
+
+import mysql from "mysql2/promise";
+
+// Erstellen eines Pools von Datenbankverbindungen
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ try {
+ // Ausführen der Datenbankabfrage
+ const query = "SELECT idprio, level, name, color FROM prio";
+ const results = await pool.query(query);
+
+ // Wichtig: Senden Sie die Antwort zurück
+ res.status(200).json(results[0]); // Da mysql2 Tuple [rows, fields] zurückgibt, wählen wir nur rows mit [0]
+ } catch (error) {
+ console.error("Fehler beim Abrufen der API", error);
+ res.status(500).json({ error: "Fehler bei der Abfrage" });
+ }
+}
diff --git a/pages/api - Kopie/talas_v5_DB/station/getAllStationsNames.js b/pages/api - Kopie/talas_v5_DB/station/getAllStationsNames.js
new file mode 100644
index 000000000..0d5d5ca05
--- /dev/null
+++ b/pages/api - Kopie/talas_v5_DB/station/getAllStationsNames.js
@@ -0,0 +1,43 @@
+// /pages/api/talas_v5_DB/station/getAllStationsNames.js
+import mysql from "mysql2/promise";
+
+// Verbindungspool-Konfiguration
+const pool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ waitForConnections: true,
+ connectionLimit: 10,
+ queueLimit: 0,
+});
+
+export default async function handler(req, res) {
+ if (req.method !== "GET") {
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+
+ try {
+ // Abrufen aller idLD und ihrer Namen
+ const [results] = await pool.query("SELECT idLD, name FROM location_device");
+
+ if (results.length === 0) {
+ return res.status(404).json({ error: "No data found" });
+ }
+
+ // Struktur der Antwort anpassen
+ const namesMap = results.reduce((map, { idLD, name }) => {
+ if (!map[idLD]) {
+ map[idLD] = name; // Stelle sicher, dass hier keine Duplikate oder Überschreibungen entstehen
+ }
+ return map;
+ }, {});
+
+ res.status(200).json(namesMap);
+ } catch (err) {
+ console.error("Fehler beim Abrufen der Daten:", err);
+ res.status(500).json({ error: "Error retrieving data from the database" });
+ }
+}
diff --git a/pages/api.zip b/pages/api.zip
new file mode 100644
index 000000000..345e83d41
Binary files /dev/null and b/pages/api.zip differ
diff --git a/pages/api/talas5/area.js b/pages/api/talas5/area.js
index 9205aa5ca..a9c399a52 100644
--- a/pages/api/talas5/area.js
+++ b/pages/api/talas5/area.js
@@ -1,40 +1,19 @@
// pages/api/talas_v5/area.js
// Lesen von talas_v5 MySQL-Datenbank -> area Tabelle enthält DAUZ Geräte
-// Wenn gebraucht wird, dann nutzen ansonsten löschen
-import mysql from "mysql";
+import getPool from "../../utils/mysqlPool"; // Verwende den Singleton-Pool
-const dbConfig = {
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
-};
-//console.log("my dbconfig: ", dbConfig);
-export default function handler(req, res) {
- const connection = mysql.createConnection(dbConfig);
+export default async function handler(req, res) {
+ try {
+ const pool = getPool(); // Hole den Pool
- connection.connect((err) => {
- if (err) {
- console.error("Fehler beim Verbinden:", err.stack);
- res.status(500).json({ error: "Verbindungsfehler zur Datenbank" });
- return;
- }
+ // Führe die Abfrage aus
+ const [results] = await pool.query("SELECT id, name FROM area WHERE id = ?", [req.query.id]);
- //console.log("Verbunden als ID", connection.threadId);
- //Fehler weil, existiertdie Tabelle auf localhost:3000 nicht
- connection.query("SELECT ..., ..., ..., ... FROM ... WHERE ... = ...", (error, results) => {
- if (error) {
- console.error("Fehler beim Abrufen der API", error);
- res.status(500).json({ error: "Fehler bei der Abfrage" });
- return;
- }
-
- // Wichtig: Senden Sie die Antwort zurück
- res.status(200).json(results);
-
- connection.end();
- });
- });
+ // Sende die Antwort zurück
+ res.status(200).json(results);
+ } catch (error) {
+ console.error("Fehler beim Abrufen der API", error);
+ res.status(500).json({ error: "Fehler bei der Abfrage" });
+ }
}
diff --git a/pages/api/talas5/location_device.js b/pages/api/talas5/location_device.js
index 9292690e0..498db9424 100644
--- a/pages/api/talas5/location_device.js
+++ b/pages/api/talas5/location_device.js
@@ -1,42 +1,34 @@
-// Importieren des mysql2 Pakets
-import mysql from "mysql2";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
-
-// Ein Hilfsfunktion, um Anfragen zu vereinfachen
-function queryDatabase(query, params) {
- return new Promise((resolve, reject) => {
- pool.query(query, params, (error, results) => {
- if (error) {
- return reject(error);
- }
- resolve(results);
- });
- });
-}
+// /pages/api/talas5/location_device.js
+import getPool from "../../../utils/mysqlPool"; // Import Singleton-Pool
// API-Handler
export default async function handler(req, res) {
- try {
- // Dein SQL-Query und die Parameter
- const sql = "SELECT idLD, iddevice, name FROM location_device WHERE iddevice = ?";
- const params = [160]; // Beispielparameter
+ const pool = getPool(); // Singleton-Pool verwenden
- // Ausführen der Datenbankabfrage
- const results = await queryDatabase(sql, params);
+ let connection;
+ try {
+ // SQL-Query and parameters
+ const sql = "SELECT idLD, iddevice, name FROM location_device WHERE iddevice = ?";
+ const params = [160]; // Example parameter
+
+ // Get a connection from the pool
+ connection = await pool.getConnection();
+
+ // Execute the query
+ const [results] = await connection.query(sql, params);
+
+ // Check if results are empty
+ if (!results.length) {
+ return res.status(404).json({ error: "Keine Geräte gefunden" });
+ }
+
+ // Respond with the results
res.status(200).json(results);
} catch (error) {
- console.error("Fehler beim Abrufen der API", error);
- res.status(500).json({ error: "Fehler bei der Abfrage" });
+ // Log and return error
+ console.error("Fehler beim Abrufen der Geräteinformationen:", error);
+ res.status(500).json({ error: "Fehler beim Abrufen der Geräteinformationen" });
+ } finally {
+ if (connection) connection.release();
}
}
diff --git a/pages/api/talas5/webserviceMap/GisStationsStatusDistrict.js b/pages/api/talas5/webserviceMap/GisStationsStatusDistrict.js
index ae7c25bde..27b0b442b 100644
--- a/pages/api/talas5/webserviceMap/GisStationsStatusDistrict.js
+++ b/pages/api/talas5/webserviceMap/GisStationsStatusDistrict.js
@@ -1,19 +1,10 @@
-// /pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Verbindungspools anstelle einer einzelnen Verbindung
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+// /pages/api/talas5/webserviceMap/GisStationsStatusDistrict.js
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+ let connection; // Verbindung deklarieren
+
const { idMap, idUser } = req.query;
if (!idMap || !idUser) {
@@ -21,22 +12,25 @@ export default async function handler(req, res) {
}
try {
+ // Verbindung aus dem Pool holen
+ connection = await pool.getConnection();
+
let onlySystem = -1;
let districtCounter = 0;
// Get onlySystem
- const [mapResult] = await pool.query("SELECT idsystem_typ FROM maps WHERE id = ?", [idMap]);
+ const [mapResult] = await connection.query("SELECT idsystem_typ FROM maps WHERE id = ?", [idMap]);
if (mapResult.length > 0) {
onlySystem = mapResult[0].idsystem_typ ?? -1;
}
// Get districtCounter
if (idUser > 0) {
- const [userLayerResult] = await pool.query("SELECT count(*) as count FROM user_User_layer1 WHERE iduser = ?", [idUser]);
+ const [userLayerResult] = await connection.query("SELECT count(*) as count FROM user_User_layer1 WHERE iduser = ?", [idUser]);
districtCounter = userLayerResult[0].count;
}
- // Building the query
+ // Query erstellen
let query = `
SELECT ld.idLD, dc.message, p.level, p.name, p.color, ld.idDevice, de.isService, dc.idIcon
FROM location as l
@@ -61,7 +55,7 @@ export default async function handler(req, res) {
}
query += ` ORDER BY p.level desc`;
- const [results] = await pool.query(query, queryParams);
+ const [results] = await connection.query(query, queryParams);
const mpss = {
IdMap: idMap.toString(),
@@ -80,5 +74,8 @@ export default async function handler(req, res) {
} catch (error) {
console.error("Fehler beim Laden der Daten:", error);
res.status(500).json({ error: "Interner Serverfehler" });
+ } finally {
+ // Stelle sicher, dass die Verbindung zurück in den Pool gegeben wird
+ if (connection) connection.release();
}
}
diff --git a/pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js b/pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
index 90c535086..7912816d4 100644
--- a/pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
+++ b/pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
@@ -1,27 +1,9 @@
// /pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
-import mysql from "mysql2";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
-
-pool.on("connection", function (connection) {
- console.log("Database connected successfully.");
-});
-
-pool.on("error", function (err) {
- console.error("Fehler beim Verbinden:", err);
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
const idMap = req.query.idMap;
if (req.method !== "GET") {
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
diff --git a/pages/api/talas_v5_DB/gisLines/readGisLines.js b/pages/api/talas_v5_DB/gisLines/readGisLines.js
index d734ed011..ce7ec97dd 100644
--- a/pages/api/talas_v5_DB/gisLines/readGisLines.js
+++ b/pages/api/talas_v5_DB/gisLines/readGisLines.js
@@ -1,19 +1,8 @@
-// /pages/api/talas_v5_DB/gisLines/readGisLines.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "GET") {
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
}
@@ -21,6 +10,7 @@ export default async function handler(req, res) {
const query = "SELECT * FROM talas_v5.gis_lines;";
try {
+ // Abrufen der Datenbankergebnisse
const [results] = await pool.query(query);
if (results.length > 0) {
res.status(200).json(results);
diff --git a/pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js b/pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js
index 4271160a0..4be22f7e4 100644
--- a/pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js
+++ b/pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js
@@ -1,18 +1,8 @@
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "POST") {
return res.status(405).json({ error: "Nur POST Methode erlaubt" });
}
@@ -52,7 +42,6 @@ export default async function handler(req, res) {
console.error("Fehler beim Aktualisieren der gis_lines:", error);
res.status(500).json({ error: "Fehler beim Aktualisieren der gis_lines" });
} finally {
- // Stelle sicher, dass die Verbindung zurückgegeben wird
if (connection) connection.release();
}
}
diff --git a/pages/api/talas_v5_DB/locationDevice/getDeviceId.js b/pages/api/talas_v5_DB/locationDevice/getDeviceId.js
index 8b2326316..00b36b4ed 100644
--- a/pages/api/talas_v5_DB/locationDevice/getDeviceId.js
+++ b/pages/api/talas_v5_DB/locationDevice/getDeviceId.js
@@ -1,19 +1,9 @@
// API in /api/talas_v5_DB/locationDevice/getDeviceId.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "GET") {
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
}
@@ -26,9 +16,14 @@ export default async function handler(req, res) {
const query = "SELECT idLD FROM location_device WHERE name = ?";
+ let connection;
+
try {
- // Ausführen der Abfrage mit dem Pool
- const [results] = await pool.query(query, [deviceName]);
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
+ // Ausführen der Abfrage
+ const [results] = await connection.query(query, [deviceName]);
+
if (results.length > 0) {
res.status(200).json({ idLD: results[0].idLD });
} else {
@@ -37,5 +32,7 @@ export default async function handler(req, res) {
} catch (error) {
console.error("Fehler beim Abrufen der Geräte-ID:", error);
res.status(500).json({ error: "Fehler beim Abrufen der Geräte-ID" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
}
}
diff --git a/pages/api/talas_v5_DB/locationDevice/locationDeviceNameById.js b/pages/api/talas_v5_DB/locationDevice/locationDeviceNameById.js
index 575541547..3649343e2 100644
--- a/pages/api/talas_v5_DB/locationDevice/locationDeviceNameById.js
+++ b/pages/api/talas_v5_DB/locationDevice/locationDeviceNameById.js
@@ -1,19 +1,9 @@
// API in /api/talas_v5_DB/locationDevice/locationDeviceNameById.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "GET") {
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
}
@@ -24,9 +14,13 @@ export default async function handler(req, res) {
return res.status(400).json({ error: "idLD ist erforderlich" });
}
+ let connection;
+
try {
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
const query = "SELECT name FROM location_device WHERE idLD = ?";
- const [results] = await pool.query(query, [idLD]);
+ const [results] = await connection.query(query, [idLD]);
if (results.length > 0) {
res.status(200).json({ name: results[0].name });
@@ -36,5 +30,7 @@ export default async function handler(req, res) {
} catch (error) {
console.error("Fehler beim Abrufen des Gerätenamens:", error);
res.status(500).json({ error: "Fehler beim Abrufen des Gerätenamens" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
}
}
diff --git a/pages/api/talas_v5_DB/locationDevice/locationDevices.js b/pages/api/talas_v5_DB/locationDevice/locationDevices.js
index 082dc2929..4b1e7bc2b 100644
--- a/pages/api/talas_v5_DB/locationDevice/locationDevices.js
+++ b/pages/api/talas_v5_DB/locationDevice/locationDevices.js
@@ -1,32 +1,28 @@
// API in /api/talas_v5_DB/locationDevice/locationDevices.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "GET") {
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
}
const query = "SELECT * FROM location_device WHERE iddevice = 160";
+ let connection;
+
try {
- // Ausführen der Abfrage mit dem Verbindungspool
- const [results] = await pool.query(query);
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
+ // Ausführen der Abfrage
+ const [results] = await connection.query(query);
res.status(200).json(results);
} catch (error) {
console.error("Fehler beim Abrufen der Geräteinformationen:", error);
res.status(500).json({ error: "Fehler beim Abrufen der Geräteinformationen" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
}
}
diff --git a/pages/api/talas_v5_DB/poiTyp/readPoiTyp.js b/pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
index baff8f83d..34fb06aaf 100644
--- a/pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
+++ b/pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
@@ -1,19 +1,9 @@
// pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Verwende den Singleton-Pool
+
if (req.method !== "GET") {
res.setHeader("Allow", ["GET"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
@@ -21,9 +11,13 @@ export default async function handler(req, res) {
const query = "SELECT * FROM poityp";
+ let connection;
+
try {
- // Ausführen der Abfrage mit dem Verbindungspool
- const [results] = await pool.query(query);
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
+ // Führe die Abfrage aus
+ const [results] = await connection.query(query);
if (results.length === 0) {
return res.status(404).json({ message: "Keine Einträge gefunden" });
@@ -33,5 +27,7 @@ export default async function handler(req, res) {
} catch (error) {
console.error("Fehler beim Abfragen der Datenbank:", error);
res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung zurück in den Pool
}
}
diff --git a/pages/api/talas_v5_DB/pois/addLocation.js b/pages/api/talas_v5_DB/pois/addLocation.js
index 864835647..98494b342 100644
--- a/pages/api/talas_v5_DB/pois/addLocation.js
+++ b/pages/api/talas_v5_DB/pois/addLocation.js
@@ -1,16 +1,9 @@
// pages/api/addLocation.js
-import mysql from "mysql";
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- connectionLimit: 10, // Maximale Anzahl gleichzeitiger Verbindungen
-});
+export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
-export default function handler(req, res) {
if (req.method === "POST") {
const { name, poiTypeId, latitude, longitude, idLD } = req.body;
console.log("Received data:", req.body); // Überprüfen der empfangenen Daten
@@ -19,17 +12,24 @@ export default function handler(req, res) {
const point = `POINT(${longitude} ${latitude})`;
const values = [name, poiTypeId, point, idLD];
- // Verwende den Pool, um eine Verbindung zu bekommen und die Query auszuführen
- pool.query(query, values, (error, results) => {
- if (error) {
- console.error("Fehler beim Einfügen des Standorts:", error);
- return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
- }
+ let connection;
+
+ try {
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
+ // Verwende die Verbindung, um die Query auszuführen
+ const [results] = await connection.query(query, values);
+
res.status(200).json({
id: results.insertId,
message: "Standort erfolgreich hinzugefügt",
});
- });
+ } catch (error) {
+ console.error("Fehler beim Einfügen des Standorts:", error);
+ res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
+ }
} else {
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
diff --git a/pages/api/talas_v5_DB/pois/deletePoi.js b/pages/api/talas_v5_DB/pois/deletePoi.js
index e9132bd6b..43ac96a9a 100644
--- a/pages/api/talas_v5_DB/pois/deletePoi.js
+++ b/pages/api/talas_v5_DB/pois/deletePoi.js
@@ -1,19 +1,9 @@
// pages/api/talas_v5_DB/pois/deletePoi.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "DELETE") {
return res.status(405).json({ error: "Nur DELETE Methode erlaubt" });
}
@@ -26,9 +16,13 @@ export default async function handler(req, res) {
const query = "DELETE FROM poi WHERE idPoi = ?";
+ let connection;
+
try {
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
// Ausführen der Abfrage mit dem Verbindungspool
- const [results] = await pool.query(query, [id]);
+ const [results] = await connection.query(query, [id]);
if (results.affectedRows > 0) {
res.status(200).json({ message: "POI erfolgreich gelöscht" });
@@ -36,7 +30,9 @@ export default async function handler(req, res) {
res.status(404).json({ error: "POI nicht gefunden" });
}
} catch (error) {
- console.error("Fehler beim Löschen des POI 3:", error);
+ console.error("Fehler beim Löschen des POI:", error);
res.status(500).json({ error: "Fehler beim Löschen des POI" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
}
}
diff --git a/pages/api/talas_v5_DB/pois/getPoiById.js b/pages/api/talas_v5_DB/pois/getPoiById.js
index 3bd2f1023..d06e1d86f 100644
--- a/pages/api/talas_v5_DB/pois/getPoiById.js
+++ b/pages/api/talas_v5_DB/pois/getPoiById.js
@@ -1,19 +1,9 @@
// pages/api/talas_v5_DB/pois/getPoiById.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "GET") {
res.setHeader("Allow", ["GET"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
@@ -27,9 +17,13 @@ export default async function handler(req, res) {
const query = "SELECT description FROM poi WHERE idPoi = ?";
+ let connection;
+
try {
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
// Ausführen der Abfrage mit dem Verbindungspool
- const [results] = await pool.query(query, [idPoi]);
+ const [results] = await connection.query(query, [idPoi]);
if (results.length === 0) {
return res.status(404).json({ error: "POI nicht gefunden" });
@@ -39,5 +33,7 @@ export default async function handler(req, res) {
} catch (error) {
console.error("Fehler bei der Abfrage:", error);
res.status(500).json({ error: "Fehler bei der Abfrage" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
}
}
diff --git a/pages/api/talas_v5_DB/pois/poi-icons.js b/pages/api/talas_v5_DB/pois/poi-icons.js
index 407704538..742260fb9 100644
--- a/pages/api/talas_v5_DB/pois/poi-icons.js
+++ b/pages/api/talas_v5_DB/pois/poi-icons.js
@@ -1,19 +1,9 @@
// pages/api/talas_v5_DB/pois/poi-icons.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "GET") {
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
}
@@ -25,12 +15,18 @@ export default async function handler(req, res) {
JOIN poiicons i ON pt.icon = i.idpoiicons;
`;
+ let connection;
+
try {
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
// Ausführen der Abfrage mit dem Verbindungspool
- const [results] = await pool.query(query);
+ const [results] = await connection.query(query);
res.status(200).json(results);
} catch (error) {
console.error("Fehler beim Abrufen der Icons:", error);
res.status(500).json({ error: "Fehler beim Abrufen der Icons" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
}
}
diff --git a/pages/api/talas_v5_DB/pois/readLocations.js b/pages/api/talas_v5_DB/pois/readLocations.js
index 308de78af..464d0df5e 100644
--- a/pages/api/talas_v5_DB/pois/readLocations.js
+++ b/pages/api/talas_v5_DB/pois/readLocations.js
@@ -1,32 +1,27 @@
// pages/api/talas_v5_DB/pois/readLocations.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
const query = `
SELECT idPoi, description, idPoiTyp, idLD, ST_AsText(position) AS position
FROM poi
`;
+ let connection;
+
try {
- // Ausführen der Abfrage mit dem Verbindungspool
- const [results] = await pool.query(query);
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
+ const [results] = await connection.query(query);
// Senden der Antwort zurück
res.status(200).json(results);
} catch (error) {
console.error("Fehler beim Abrufen der API:", error);
res.status(500).json({ error: "Fehler bei der Abfrage" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
}
}
diff --git a/pages/api/talas_v5_DB/pois/updateLocation.js b/pages/api/talas_v5_DB/pois/updateLocation.js
index ee61070f2..dafa9ce20 100644
--- a/pages/api/talas_v5_DB/pois/updateLocation.js
+++ b/pages/api/talas_v5_DB/pois/updateLocation.js
@@ -1,20 +1,9 @@
// pages/api/talas_v5_DB/pois/updateLocation.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- charset: "utf8mb4",
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
if (req.method !== "POST") {
res.setHeader("Allow", ["POST"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
@@ -28,8 +17,12 @@ export default async function handler(req, res) {
const query = "UPDATE poi SET position = POINT(?, ?) WHERE idPoi = ?";
+ let connection;
+
try {
- const [result] = await pool.query(query, [longitude, latitude, id]);
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
+ const [result] = await connection.query(query, [longitude, latitude, id]);
if (result.affectedRows > 0) {
res.status(200).json({ success: true });
@@ -39,44 +32,7 @@ export default async function handler(req, res) {
} catch (error) {
console.error("Fehler beim Aktualisieren der Position:", error);
res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
}
}
-
-/* import mysql from "mysql";
-import util from "util";
-
-const dbConfig = {
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- charset: "utf8mb4",
-};
-
-export default async function handler(req, res) {
- if (req.method !== "POST") {
- res.setHeader("Allow", ["POST"]);
- return res.status(405).end(`Method ${req.method} Not Allowed`);
- }
-
- const { id, latitude, longitude } = req.body;
-
- const connection = mysql.createConnection(dbConfig);
- // Promisify the query method
- const query = util.promisify(connection.query).bind(connection);
-
- try {
- await query("UPDATE poi SET position = POINT(?, ?) WHERE idPoi = ?", [
- longitude,
- latitude,
- id,
- ]);
- res.status(200).json({ success: true });
- } catch (error) {
- console.error(error);
- res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
- } finally {
- connection.end();
- }
-} */
diff --git a/pages/api/talas_v5_DB/pois/updatePoi.js b/pages/api/talas_v5_DB/pois/updatePoi.js
index bc3356a2f..1b46ec65e 100644
--- a/pages/api/talas_v5_DB/pois/updatePoi.js
+++ b/pages/api/talas_v5_DB/pois/updatePoi.js
@@ -1,19 +1,9 @@
// pages/api/talas_v5_DB/pois/updatePoi.js
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Verwende den Singleton-Pool
+
if (req.method !== "POST") {
return res.status(405).json({ error: "Nur POST Methode erlaubt" });
}
@@ -30,8 +20,12 @@ export default async function handler(req, res) {
WHERE idPoi = ?
`;
+ let connection;
+
try {
- const [results] = await pool.query(query, [description, idPoiTyp, idLD, idPoi]);
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
+ const [results] = await connection.query(query, [description, idPoiTyp, idLD, idPoi]);
if (results.affectedRows > 0) {
res.status(200).json({ message: "POI erfolgreich aktualisiert" });
@@ -41,5 +35,7 @@ export default async function handler(req, res) {
} catch (error) {
console.error("Fehler beim Aktualisieren des POI:", error);
res.status(500).json({ error: "Fehler beim Aktualisieren des POI" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung zurück in den Pool
}
}
diff --git a/pages/api/talas_v5_DB/priorityConfig.js b/pages/api/talas_v5_DB/priorityConfig.js
index 719007020..a2a24d1c6 100644
--- a/pages/api/talas_v5_DB/priorityConfig.js
+++ b/pages/api/talas_v5_DB/priorityConfig.js
@@ -2,28 +2,18 @@
// in tals5 http://10.10.0.13/talas5/Management/PriorityConfig.aspx beinhaltet die Tabelle prio die Prioritäten der Meldungen (Level 1-4) oder (0-4) je nachdem DB-Design
// das ist die API, die die Prioritäten zurückgibt
-import mysql from "mysql2/promise";
-
-// Erstellen eines Pools von Datenbankverbindungen
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../utils/mysqlPool"; // Singleton-Pool importieren
export default async function handler(req, res) {
+ const pool = getPool(); // Singleton-Pool verwenden
+
try {
// Ausführen der Datenbankabfrage
const query = "SELECT idprio, level, name, color FROM prio";
- const results = await pool.query(query);
+ const [results] = await pool.query(query);
// Wichtig: Senden Sie die Antwort zurück
- res.status(200).json(results[0]); // Da mysql2 Tuple [rows, fields] zurückgibt, wählen wir nur rows mit [0]
+ res.status(200).json(results); // Nur rows werden zurückgegeben
} catch (error) {
console.error("Fehler beim Abrufen der API", error);
res.status(500).json({ error: "Fehler bei der Abfrage" });
diff --git a/pages/api/talas_v5_DB/station/getAllStationsNames.js b/pages/api/talas_v5_DB/station/getAllStationsNames.js
index 0d5d5ca05..1bf158cb2 100644
--- a/pages/api/talas_v5_DB/station/getAllStationsNames.js
+++ b/pages/api/talas_v5_DB/station/getAllStationsNames.js
@@ -1,27 +1,21 @@
// /pages/api/talas_v5_DB/station/getAllStationsNames.js
-import mysql from "mysql2/promise";
-
-// Verbindungspool-Konfiguration
-const pool = mysql.createPool({
- host: process.env.DB_HOST,
- user: process.env.DB_USER,
- password: process.env.DB_PASSWORD,
- database: process.env.DB_NAME,
- port: process.env.DB_PORT,
- waitForConnections: true,
- connectionLimit: 10,
- queueLimit: 0,
-});
+import getPool from "../../../../utils/mysqlPool"; // Importiere den Singleton-Pool
export default async function handler(req, res) {
+ const pool = getPool(); // Verwende den Singleton-Pool
+
if (req.method !== "GET") {
res.setHeader("Allow", ["GET"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
+ let connection;
+
try {
+ connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
+
// Abrufen aller idLD und ihrer Namen
- const [results] = await pool.query("SELECT idLD, name FROM location_device");
+ const [results] = await connection.query("SELECT idLD, name FROM location_device");
if (results.length === 0) {
return res.status(404).json({ error: "No data found" });
@@ -39,5 +33,7 @@ export default async function handler(req, res) {
} catch (err) {
console.error("Fehler beim Abrufen der Daten:", err);
res.status(500).json({ error: "Error retrieving data from the database" });
+ } finally {
+ if (connection) connection.release(); // Gib die Verbindung zurück in den Pool
}
}
diff --git a/utils/mapFeatures.js b/utils/mapFeatures.js
index 59a327681..8cba33e7f 100644
--- a/utils/mapFeatures.js
+++ b/utils/mapFeatures.js
@@ -131,40 +131,7 @@ export const setupMarkers = async (
export const setupPolylines = (map, linePositions, lineColors, tooltipContents, setNewCoords, tempMarker, currentZoom, currentCenter) => {
const markers = [];
const polylines = [];
- let isMouseOverMenuItem = false;
- const checkMouseOverMenu = () => {
- if (!isMouseOverMenuItem) {
- //showContextMenuItemByIndex(map, 0);
- //showContextMenuItemByIndex(map, 1);
- //closeContextMenu(); // Kontextmenü schließen, wenn die Maus nicht mehr darüber ist
- }
- };
-
- const handleMouseOverMenuItem = () => {
- isMouseOverMenuItem = true;
- };
-
- const handleMouseOutMenuItem = () => {
- isMouseOverMenuItem = false;
- setTimeout(checkMouseOverMenu, 500); // kleine Verzögerung, um sicherzustellen, dass es keine schnellen Bewegungen sind
- };
-
- const closeContextMenu = () => {
- const contextMenuElement = document.querySelector(".leaflet-contextmenu");
- if (contextMenuElement) {
- contextMenuElement.style.display = "none"; // Kontextmenü ausblenden
- }
- };
-
- const handleOutsideClick = (event) => {
- const contextMenuElement = document.querySelector(".leaflet-contextmenu");
- if (contextMenuElement && !contextMenuElement.contains(event.target)) {
- //closeContextMenu(); // Kontextmenü schließen, wenn der Klick außerhalb stattfindet
- }
- };
-
- //document.addEventListener("mousedown", handleOutsideClick);
linePositions.forEach((lineData, lineIndex) => {
const lineMarkers = [];
lineData.coordinates.forEach((coord, index) => {
@@ -269,8 +236,6 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
const polyline = L.polyline(lineData.coordinates, {
color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000",
contextmenu: true,
- idLD: lineData.idLD, // Füge die idLD zur Polyline hinzu
- idModul: lineData.idModul, // Füge die idModul zur Polyline hinzu
contextmenuItems: [
{
text: "Stützpunkt hinzufügen",
@@ -290,21 +255,12 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
}).addTo(map);
polyline.on("mouseover", (e) => {
- polyline.setStyle({ weight: 15 });
- });
-
- polyline.on("mousedown", (e) => {
- polyline.setStyle({ weight: 15 });
- });
-
- polyline.on("mouseup", (e) => {
- polyline.setStyle({ weight: 15 });
+ polyline.setStyle({ weight: 10 });
});
polyline.on("mouseout", (e) => {
polyline.setStyle({ weight: 3 });
polyline.setStyle({ color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000" });
- //setTimeout(checkMouseOverMenu, 500);
});
polyline.bindTooltip(tooltipContents[`${lineData.idLD}-${lineData.idModul}`] || "Standard-Tooltip-Inhalt", {
@@ -316,7 +272,5 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
markers.push(...lineMarkers);
});
- // Add listeners to the context menu items
- const contextMenuElement = document.querySelector(".leaflet-contextmenu"); // Assuming the context menu class is 'leaflet-contextmenu'
return { markers, polylines };
};
diff --git a/utils/mapInitialization.js b/utils/mapInitialization.js
index 71e49a733..ffbc761b5 100644
--- a/utils/mapInitialization.js
+++ b/utils/mapInitialization.js
@@ -40,14 +40,40 @@ export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItems
text: "Station Öffnen (Tab)",
icon: "/img/screen_new.png",
callback: (e) => {
- const clickedTarget = lastClickedTarget || findNearestPolyline(initMap, e.latlng); // Verwende zwischengespeichertes Ziel oder die nächstgelegene Linie
+ const clickedTarget = lastClickedTarget || e.relatedTarget || e.layer;
+
+ if (!clickedTarget) {
+ console.error("Kein gültiges Ziel im Kontextmenü");
+ return;
+ }
+
+ // Prüfen, ob das Element eine Station (Marker) oder Linie (Polyline) ist
+ if (clickedTarget instanceof L.Marker) {
+ console.log("Marker angeklickt");
+ openInNewTab(e, clickedTarget);
+ } else if (clickedTarget instanceof L.Polyline) {
+ console.log("Linie angeklickt:", clickedTarget.options.idLD); // Hier kannst du die ID oder andere Optionen der Polyline verwenden
+ // Optional: Funktion zum Öffnen der Linie implementieren
+ openInNewTab(e, clickedTarget);
+ } else {
+ console.error("Unbekanntes Element");
+ }
+ },
+ },
+
+ /* callback: (e) => {
+ //Wenn Kein Station oder ein Station ist
+ const clickedMarker = e.relatedTarget; // Zugriff auf den Marker, der das Event ausgelöst hat
+ openInNewTab(e, clickedMarker);
+ //wenn Linie ist (polyline)
+ const clickedTarget = lastClickedTarget || findNearestPolyline(initMap, e.latlng); // Verwende zwischengespeichertes Ziel oder die nächstgelegene Linie
if (clickedTarget) {
openInNewTab(e, clickedTarget); // Gemeinsame Funktion für Linien und Stationen
} else {
console.error("Kein gültiges Ziel im Kontextmenü");
- }
+ }
},
- },
+ }, */
"-",
],
});
diff --git a/utils/mysqlPool.js b/utils/mysqlPool.js
new file mode 100644
index 000000000..266a6ecdf
--- /dev/null
+++ b/utils/mysqlPool.js
@@ -0,0 +1,40 @@
+import mysql from "mysql2/promise";
+
+// Variablen für den Singleton-Pool
+let cachedPool;
+let connectionCount = 0; // Zähler für die aktiven Verbindungen
+
+// Funktion zum Abrufen des Pools
+function getPool() {
+ if (!cachedPool) {
+ cachedPool = mysql.createPool({
+ host: process.env.DB_HOST,
+ user: process.env.DB_USER,
+ password: process.env.DB_PASSWORD,
+ database: process.env.DB_NAME,
+ port: process.env.DB_PORT,
+ connectionLimit: 10, // Setze ein Limit für gleichzeitige Verbindungen
+ waitForConnections: true,
+ queueLimit: 0, // Unbegrenzte Warteschlange für Verbindungen
+ });
+
+ // Ereignisse für das Protokollieren der Verbindungsstatistiken
+ cachedPool.on("acquire", () => {
+ connectionCount++;
+ console.log("Connection acquired. Active connections: ", connectionCount);
+ });
+
+ cachedPool.on("release", () => {
+ connectionCount--;
+ console.log("Connection released. Active connections: ", connectionCount);
+ });
+
+ cachedPool.on("enqueue", () => {
+ console.log("Waiting for available connection slot.");
+ });
+ }
+
+ return cachedPool;
+}
+
+export default getPool;