polylines tooltip content
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
// 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: "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",
|
||||
|
||||
34
pages/api/gis-proxy.js
Normal file
34
pages/api/gis-proxy.js
Normal file
@@ -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") || "";
|
||||
});
|
||||
};
|
||||
@@ -2,13 +2,24 @@
|
||||
// http://10.10.0.13/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict
|
||||
//In DB gis_lines idLD und idModul anpassen entsprechend
|
||||
|
||||
export default function handler(req, res) {
|
||||
// /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",
|
||||
@@ -19,7 +30,7 @@ export default function handler(req, res) {
|
||||
Level: 4,
|
||||
PrioColor: "#FFFF00",
|
||||
PrioName: "system",
|
||||
Value: "?",
|
||||
Value: "10 MOhm",
|
||||
},
|
||||
{
|
||||
IdLD: 25440,
|
||||
@@ -32,7 +43,7 @@ export default function handler(req, res) {
|
||||
Level: 4,
|
||||
PrioColor: "#FF0000",
|
||||
PrioName: "system",
|
||||
Value: "?",
|
||||
Value: "10 MOhm",
|
||||
},
|
||||
{
|
||||
IdLD: 25440,
|
||||
@@ -44,8 +55,8 @@ export default function handler(req, res) {
|
||||
Level: 4,
|
||||
PrioColor: "#FF00FF",
|
||||
PrioName: "system",
|
||||
Value: "?",
|
||||
},
|
||||
Value: "10 MOhm",
|
||||
}, */
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ const dbConfig = {
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT,
|
||||
};
|
||||
console.log("my dbconfig: ", dbConfig);
|
||||
//console.log("my dbconfig: ", dbConfig);
|
||||
export default function handler(req, res) {
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
|
||||
@@ -22,22 +22,19 @@ export default function handler(req, res) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Verbunden als ID", connection.threadId);
|
||||
//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();
|
||||
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();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
// pages/api/talas_v5/location_device.js
|
||||
// talas_v5 Datenbank -> location_device Tabelle enthält DAUZ Geräte
|
||||
// Importieren des mysql2 Pakets
|
||||
import mysql from "mysql2";
|
||||
|
||||
import mysql from "mysql";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
console.log("my dbconfig: ", dbConfig);
|
||||
export default function handler(req, res) {
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
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 idLD, iddevice, iddevice, name FROM location_device WHERE iddevice = 160",
|
||||
(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();
|
||||
// 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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,42 @@
|
||||
// /pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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) {
|
||||
res.status(400).json({ error: "idMap and idUser are required" });
|
||||
return;
|
||||
return res.status(400).json({ error: "idMap and idUser are required" });
|
||||
}
|
||||
|
||||
let connection;
|
||||
try {
|
||||
connection = await mysql.createConnection(dbConfig);
|
||||
|
||||
let onlySystem = -1;
|
||||
let districtCounter = 0;
|
||||
|
||||
// Get onlySystem
|
||||
const [mapResult] = await connection.execute(
|
||||
"SELECT idsystem_typ FROM maps WHERE id = ?",
|
||||
[idMap]
|
||||
);
|
||||
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 connection.execute(
|
||||
"SELECT count(*) as count FROM user_User_layer1 WHERE iduser = ?",
|
||||
[idUser]
|
||||
);
|
||||
const [userLayerResult] = await pool.query("SELECT count(*) as count FROM user_User_layer1 WHERE iduser = ?", [idUser]);
|
||||
districtCounter = userLayerResult[0].count;
|
||||
}
|
||||
|
||||
// Get GisStatusStations
|
||||
// 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
|
||||
@@ -55,25 +50,18 @@ export default async function handler(req, res) {
|
||||
WHERE p.level < 100 AND co.X > 0
|
||||
`;
|
||||
|
||||
if (districtCounter > 0) {
|
||||
query += ` AND a.iddistrict IN (SELECT iddistrict FROM user_user_layer1 WHERE iduser = ?)`;
|
||||
}
|
||||
|
||||
if (onlySystem >= 0) {
|
||||
query += ` AND de.idsystem_typ = ?`;
|
||||
}
|
||||
|
||||
query += ` ORDER BY p.level desc`;
|
||||
|
||||
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 connection.execute(query, queryParams);
|
||||
const [results] = await pool.query(query, queryParams);
|
||||
|
||||
const mpss = {
|
||||
IdMap: idMap.toString(),
|
||||
@@ -92,9 +80,5 @@ 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 {
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
import mysql from "mysql";
|
||||
// /pages/api/talas5/webserviceMap/gisStationsMeasurementsSQL.js
|
||||
import mysql from "mysql2";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
});
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
console.log("Database connected successfully.");
|
||||
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) {
|
||||
@@ -23,7 +27,7 @@ export default function handler(req, res) {
|
||||
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
||||
}
|
||||
|
||||
connection.query(`
|
||||
const sqlQuery = `
|
||||
SELECT
|
||||
ld.idLD,
|
||||
dp.idDP,
|
||||
@@ -34,37 +38,37 @@ export default function handler(req, res) {
|
||||
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 = ${idMap}
|
||||
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
|
||||
`, (error, results) => {
|
||||
`;
|
||||
|
||||
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" });
|
||||
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) => ({
|
||||
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,
|
||||
IdLocation: row.idLocation,
|
||||
Area_Name: row.Area_Name,
|
||||
})),
|
||||
};
|
||||
|
||||
res.json(response);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,34 @@
|
||||
// /pages/api/talas_v5_DB/gisLines/readGisLines.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
console.log("Database connected successfully.");
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
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;";
|
||||
connection.query(query, (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" });
|
||||
}
|
||||
|
||||
try {
|
||||
const [results] = await pool.query(query);
|
||||
if (results.length > 0) {
|
||||
res.json(results);
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
// /pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
console.log("Database connected successfully.");
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
export default async function handler(req, res) {
|
||||
if (req.method !== "POST") {
|
||||
return res.status(405).json({ error: "Nur POST Methode erlaubt" });
|
||||
}
|
||||
@@ -30,39 +24,35 @@ export default function handler(req, res) {
|
||||
|
||||
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 = ?;";
|
||||
const query = "UPDATE talas_v5.gis_lines SET points = ST_GeomFromText(?) WHERE idLD = ? AND idModul = ?;";
|
||||
|
||||
connection.beginTransaction((err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
connection.query(
|
||||
query,
|
||||
[newLineString, idLD, idModul],
|
||||
(error, results, fields) => {
|
||||
if (error) {
|
||||
return connection.rollback(() => {
|
||||
console.error("Fehler beim Aktualisieren der gis_lines:", error);
|
||||
res
|
||||
.status(500)
|
||||
.json({ error: "Fehler beim Aktualisieren der gis_lines" });
|
||||
});
|
||||
}
|
||||
let connection;
|
||||
|
||||
connection.commit((err) => {
|
||||
if (err) {
|
||||
return connection.rollback(() => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
console.log("Transaction Complete.");
|
||||
res.status(200).json({
|
||||
success: "Updated successfully.",
|
||||
affectedRows: results.affectedRows,
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,41 @@
|
||||
// API in /api/talas_v5_DB/locationDevice/getDeviceId.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
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 = ?";
|
||||
connection.query(query, [deviceName], (error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Abrufen der Geräte-ID:", error);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Fehler beim Abrufen der Geräte-ID" });
|
||||
}
|
||||
|
||||
try {
|
||||
// Ausführen der Abfrage mit dem Pool
|
||||
const [results] = await pool.query(query, [deviceName]);
|
||||
if (results.length > 0) {
|
||||
res.json({ idLD: results[0].idLD });
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,40 @@
|
||||
// API in /api/talas_v5_DB/locationDevice/locationDeviceNameById.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
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;
|
||||
|
||||
const query = "SELECT name FROM location_device WHERE idLD = ?";
|
||||
connection.query(query, [idLD], (error, results) => {
|
||||
if (error) {
|
||||
console.error(
|
||||
"Fehler beim Abrufen des Gerätenamens in locationDeviceNameById.js :",
|
||||
error
|
||||
);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Fehler beim Abrufen des Gerätenamens" });
|
||||
}
|
||||
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.json({ name: results[0].name });
|
||||
res.status(200).json({ name: results[0].name });
|
||||
} else {
|
||||
res.status(404).json({ error: "Gerät nicht gefunden" });
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,32 @@
|
||||
// API in /api/talas_v5_DB/locationDevice/locationDevices.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
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";
|
||||
connection.query(query, (error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Abrufen der Geräteinformationen:", error);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Fehler beim Abrufen der Geräteinformationen" });
|
||||
}
|
||||
res.json(results);
|
||||
});
|
||||
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,37 @@
|
||||
// pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
// Erstellen eines Pools von Datenbankverbindungen
|
||||
const pool = mysql.createPool({
|
||||
//connectionLimit: 10,
|
||||
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 function handler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
const query = "SELECT * FROM poityp";
|
||||
|
||||
pool.query(query, (error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Abfragen der Datenbank:", error);
|
||||
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
||||
}
|
||||
|
||||
if (results.length === 0) {
|
||||
return res.status(404).json({ message: "Keine Einträge gefunden" });
|
||||
}
|
||||
|
||||
res.status(200).json(results);
|
||||
});
|
||||
} else {
|
||||
export default async function handler(req, res) {
|
||||
if (req.method !== "GET") {
|
||||
res.setHeader("Allow", ["GET"]);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,45 @@
|
||||
// pages/api/talas_v5_DB/pois/addLocation.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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 function handler(req, res) {
|
||||
export default async 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 connection = mysql.createConnection(dbConfig);
|
||||
|
||||
const query =
|
||||
"INSERT INTO poi (description, idPoiTyp, position, idLD) VALUES (?, ?, ST_GeomFromText(?),?)";
|
||||
if (!name || !poiTypeId || !latitude || !longitude || !idLD) {
|
||||
return res.status(400).json({ error: "Alle Felder sind erforderlich" });
|
||||
}
|
||||
|
||||
const query = `
|
||||
INSERT INTO poi (description, idPoiTyp, position, idLD)
|
||||
VALUES (?, ?, ST_GeomFromText(?), ?)
|
||||
`;
|
||||
const point = `POINT(${longitude} ${latitude})`;
|
||||
const values = [name, poiTypeId, point, idLD]; // Stellen Sie sicher, dass poiTypeId korrekt ist
|
||||
const values = [name, poiTypeId, point, idLD];
|
||||
|
||||
connection.query(query, values, (error, results) => {
|
||||
connection.end();
|
||||
if (error) {
|
||||
console.error("Fehler beim Einfügen des Standorts:", error);
|
||||
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
||||
}
|
||||
try {
|
||||
// Ausführen der Abfrage mit dem Verbindungspool
|
||||
const [results] = await pool.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" });
|
||||
}
|
||||
} else {
|
||||
res.setHeader("Allow", ["POST"]);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
// pages/api/talas_v5_DB/pois/deletePoi.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
// Datenbankkonfiguration
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
console.log("Verbunden als ID", connection.threadId);
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
export default async function handler(req, res) {
|
||||
if (req.method !== "DELETE") {
|
||||
return res.status(405).json({ error: "Nur DELETE Methode erlaubt" });
|
||||
}
|
||||
@@ -31,15 +25,18 @@ export default function handler(req, res) {
|
||||
}
|
||||
|
||||
const query = "DELETE FROM poi WHERE idPoi = ?";
|
||||
connection.query(query, [id], (error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Löschen des POI:", error);
|
||||
return res.status(500).json({ error: "Fehler beim Löschen des POI" });
|
||||
}
|
||||
|
||||
try {
|
||||
// Ausführen der Abfrage mit dem Verbindungspool
|
||||
const [results] = await pool.query(query, [id]);
|
||||
|
||||
if (results.affectedRows > 0) {
|
||||
res.json({ message: "POI erfolgreich gelöscht" });
|
||||
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:", error);
|
||||
res.status(500).json({ error: "Fehler beim Löschen des POI" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,43 @@
|
||||
// pages/api/talas_v5_DB/pois/getPoiById.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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 function handler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
const { idPoi } = req.query;
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Verbindungsfehler zur Datenbank" });
|
||||
}
|
||||
|
||||
const query = "SELECT description FROM poi WHERE idPoi = ?";
|
||||
connection.query(query, [idPoi], (error, results) => {
|
||||
connection.end();
|
||||
if (error) {
|
||||
console.error("Fehler bei der Abfrage:", error);
|
||||
return res.status(500).json({ error: "Fehler bei der Abfrage" });
|
||||
}
|
||||
if (results.length === 0) {
|
||||
return res.status(404).json({ error: "POI nicht gefunden" });
|
||||
}
|
||||
res.status(200).json(results[0]);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
export default async function handler(req, res) {
|
||||
if (req.method !== "GET") {
|
||||
res.setHeader("Allow", ["GET"]);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,36 @@
|
||||
// pages/api/talas_v5_DB/pois/poi-icons.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
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;`;
|
||||
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;
|
||||
`;
|
||||
|
||||
connection.query(query, (error, results) => {
|
||||
try {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
res.json(results);
|
||||
} catch (err) {
|
||||
console.error("Fehler beim Abrufen der icons:", err);
|
||||
res.status(500).json({ error: "Fehler beim Abrufen der icons" });
|
||||
}
|
||||
});
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,32 @@
|
||||
// pages/api/talas_v5_DB/pois/readLocations.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
console.log("my dbconfig: ", dbConfig);
|
||||
export default function handler(req, res) {
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
res.status(500).json({ error: "Verbindungsfehler zur Datenbank" });
|
||||
return;
|
||||
}
|
||||
export default async function handler(req, res) {
|
||||
const query = `
|
||||
SELECT idPoi, description, idPoiTyp, idLD, ST_AsText(position) AS position
|
||||
FROM poi
|
||||
`;
|
||||
|
||||
console.log("Verbunden als ID", connection.threadId);
|
||||
try {
|
||||
// Ausführen der Abfrage mit dem Verbindungspool
|
||||
const [results] = await pool.query(query);
|
||||
|
||||
connection.query(
|
||||
"SELECT idPoi, description, idPoiTyp, idLD, ST_AsText(position) AS position FROM poi",
|
||||
(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);
|
||||
console.log(
|
||||
"--------------- location.js ---------------",
|
||||
"results in location.js : ",
|
||||
results,
|
||||
"---------------------- location.js end ---------------------------"
|
||||
);
|
||||
connection.end();
|
||||
}
|
||||
);
|
||||
});
|
||||
// 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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,48 @@
|
||||
// pages/api/talas_v5_DB/pois/updateLocation.js
|
||||
import mysql from "mysql";
|
||||
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 = {
|
||||
@@ -36,4 +79,4 @@ export default async function handler(req, res) {
|
||||
} finally {
|
||||
connection.end();
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
@@ -1,53 +1,45 @@
|
||||
// pages/api/talas_v5_DB/pois/updatePoi.js
|
||||
import mysql from "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
console.log("Verbunden als ID", connection.threadId);
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
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; // Stellen Sie sicher, dass die Felder korrekt benannt sind
|
||||
|
||||
console.log("Empfangene Daten:", req.body); // Loggen der empfangenen Daten zur Überprüfung
|
||||
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 = ?";
|
||||
connection.query(
|
||||
query,
|
||||
[description, idPoiTyp, idLD, idPoi],
|
||||
(error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Aktualisieren des POI:", error);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Fehler beim Aktualisieren des POI" });
|
||||
}
|
||||
if (results.affectedRows > 0) {
|
||||
res.json({ message: "POI erfolgreich aktualisiert" });
|
||||
} else {
|
||||
res.status(404).json({ error: "POI nicht gefunden" });
|
||||
}
|
||||
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" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,42 +2,30 @@
|
||||
// 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 "mysql";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const dbConfig = {
|
||||
// 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,
|
||||
};
|
||||
console.log("my dbconfig: ", dbConfig);
|
||||
export default function handler(req, res) {
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
res.status(500).json({ error: "Verbindungsfehler zur Datenbank" });
|
||||
return;
|
||||
}
|
||||
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);
|
||||
|
||||
console.log("Verbunden als ID", connection.threadId);
|
||||
//Fehler weil, existiertdie Tabelle auf localhost:3000 nicht
|
||||
connection.query(
|
||||
"SELECT idprio, level, name, color FROM prio ",
|
||||
(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();
|
||||
}
|
||||
);
|
||||
});
|
||||
// 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" });
|
||||
}
|
||||
}
|
||||
|
||||
31
pages/api/talas_v5_DB/station/getStationNameByIdLD.js
Normal file
31
pages/api/talas_v5_DB/station/getStationNameByIdLD.js
Normal file
@@ -0,0 +1,31 @@
|
||||
// /pages/api/talas_v5_DB/station/getStationNameByIdLD.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 {
|
||||
// Verwenden des Verbindungspools, um die Abfrage auszuführen
|
||||
const [results] = await pool.query("SELECT * FROM location_device");
|
||||
|
||||
res.status(200).json(results);
|
||||
} catch (err) {
|
||||
console.error("Fehler beim Abrufen der Daten:", err);
|
||||
res.status(500).json({ error: "Error retrieving data from the database" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user