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