42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
// pages/api/talas_v5_DB/pois/updatePoi.js
|
|
import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
|
|
|
|
export default async function handler(req, res) {
|
|
const pool = getPool(); // Verwende den Singleton-Pool
|
|
|
|
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 poi
|
|
SET description = ?, idPoiTyp = ?, idLD = ?
|
|
WHERE idPoi = ?
|
|
`;
|
|
|
|
let connection;
|
|
|
|
try {
|
|
connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
|
|
|
|
const [results] = await connection.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" });
|
|
} finally {
|
|
if (connection) connection.release(); // Gib die Verbindung zurück in den Pool
|
|
}
|
|
}
|