54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
// pages/api/updatePoi.js
|
|
import mysql from "mysql";
|
|
|
|
const dbConfig = {
|
|
host: process.env.DB_HOST,
|
|
user: process.env.DB_USER,
|
|
password: process.env.DB_PASSWORD,
|
|
database: process.env.DB_NAME,
|
|
port: process.env.DB_PORT,
|
|
};
|
|
|
|
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);
|
|
});
|
|
|
|
export default 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
|
|
|
|
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, idPoi, idLD],
|
|
(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" });
|
|
}
|
|
}
|
|
);
|
|
}
|