polylines tooltip content
This commit is contained in:
@@ -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