mysql createPool
This commit is contained in:
34
pages/api - Kopie/talas_v5_DB/gisLines/readGisLines.js
Normal file
34
pages/api - Kopie/talas_v5_DB/gisLines/readGisLines.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
41
pages/api - Kopie/talas_v5_DB/locationDevice/getDeviceId.js
Normal file
41
pages/api - Kopie/talas_v5_DB/locationDevice/getDeviceId.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
@@ -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" });
|
||||
}
|
||||
}
|
||||
@@ -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" });
|
||||
}
|
||||
}
|
||||
37
pages/api - Kopie/talas_v5_DB/poiTyp/readPoiTyp.js
Normal file
37
pages/api - Kopie/talas_v5_DB/poiTyp/readPoiTyp.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
37
pages/api - Kopie/talas_v5_DB/pois/addLocation.js
Normal file
37
pages/api - Kopie/talas_v5_DB/pois/addLocation.js
Normal file
@@ -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`);
|
||||
}
|
||||
}
|
||||
42
pages/api - Kopie/talas_v5_DB/pois/deletePoi.js
Normal file
42
pages/api - Kopie/talas_v5_DB/pois/deletePoi.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
43
pages/api - Kopie/talas_v5_DB/pois/getPoiById.js
Normal file
43
pages/api - Kopie/talas_v5_DB/pois/getPoiById.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
36
pages/api - Kopie/talas_v5_DB/pois/poi-icons.js
Normal file
36
pages/api - Kopie/talas_v5_DB/pois/poi-icons.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
32
pages/api - Kopie/talas_v5_DB/pois/readLocations.js
Normal file
32
pages/api - Kopie/talas_v5_DB/pois/readLocations.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
82
pages/api - Kopie/talas_v5_DB/pois/updateLocation.js
Normal file
82
pages/api - Kopie/talas_v5_DB/pois/updateLocation.js
Normal file
@@ -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();
|
||||
}
|
||||
} */
|
||||
45
pages/api - Kopie/talas_v5_DB/pois/updatePoi.js
Normal file
45
pages/api - Kopie/talas_v5_DB/pois/updatePoi.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
31
pages/api - Kopie/talas_v5_DB/priorityConfig.js
Normal file
31
pages/api - Kopie/talas_v5_DB/priorityConfig.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
43
pages/api - Kopie/talas_v5_DB/station/getAllStationsNames.js
Normal file
43
pages/api - Kopie/talas_v5_DB/station/getAllStationsNames.js
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user