46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
// pages/api/talas_v5_DB/pois/deletePoi.js
|
|
import mysql from "mysql";
|
|
|
|
// Datenbankkonfiguration
|
|
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 !== "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 = ?";
|
|
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" });
|
|
}
|
|
if (results.affectedRows > 0) {
|
|
res.json({ message: "POI erfolgreich gelöscht" });
|
|
} else {
|
|
res.status(404).json({ error: "POI nicht gefunden" });
|
|
}
|
|
});
|
|
}
|