Files
nodeMap/pages/api/talas_v5_DB/area/updateArea.js
ISA 3896381a8f Debug-Logging zentralisiert: Nutzung von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt und auf getDebugLog() mit config.json umgestellt
- Alle Vorkommen von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt
- Debug-Konfiguration erfolgt jetzt ausschließlich über public/config.json
- getDebugLog()-Utility überall verwendet
- .env-Dateien werden für Debug-Logging nicht mehr benötigt
- Alle betroffenen Komponenten, Services und API
2025-08-22 11:10:40 +02:00

61 lines
1.8 KiB
JavaScript

// /pages/api/talas_v5_DB/area/updateArea.js
import getPool from "../../../../utils/mysqlPool";
import { getDebugLog } from "../../../../utils/configUtils";
export default async function handler(req, res) {
if (getDebugLog()) {
console.log("Request erhalten:", req.method, req.body); // Debugging
}
const pool = getPool();
// Prüfe, ob die Methode PUT ist
if (req.method !== "PUT") {
return res.status(405).json({ error: "Nur PUT Methode erlaubt" });
}
// Daten aus dem Request-Body extrahieren
const { idLocation, idMap, x, y } = req.body;
if (!idLocation || !idMap || x === undefined || y === undefined) {
return res
.status(400)
.json({ error: "Alle Felder (idLocation, idMap, x, y) sind erforderlich" });
}
let connection;
try {
// Verbindung zur Datenbank herstellen
connection = await pool.getConnection();
const query =
"UPDATE location_coordinates SET x = ?, y = ? WHERE idLocation = ? AND idMaps = ?";
const [result] = await connection.query(query, [x, y, idLocation, idMap]);
// Erfolgreiche Aktualisierung prüfen
if (result.affectedRows > 0) {
return res
.status(200)
.json({ success: true, message: "Koordinaten erfolgreich aktualisiert" });
} else {
return res
.status(404)
.json({ error: "Kein Eintrag gefunden, der aktualisiert werden konnte" });
}
} catch (error) {
console.error("Fehler beim Aktualisieren der Koordinaten:", error);
return res
.status(500)
.json({ error: "Interner Serverfehler beim Aktualisieren der Koordinaten" });
} finally {
if (connection) {
connection.release();
}
// Sicherheitshalber eine Standardantwort senden, falls keine vorherige Antwort existiert
if (!res.headersSent) {
res.status(500).json({ error: "Keine Antwort vom Server" });
}
}
}