// /pages/api/talas_v5_DB/device/getAllStationsNames.js import getPool from "../../../../utils/mysqlPool"; // Importiere den Singleton-Pool export default async function handler(req, res) { const pool = getPool(); // Verwende den Singleton-Pool if (req.method !== "GET") { res.setHeader("Allow", ["GET"]); return res.status(405).end(`Method ${req.method} Not Allowed`); } let connection; try { connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool // Abrufen aller idLD und ihrer Namen const [results] = await connection.query("SELECT idLD, name FROM location_device"); if (results.length === 0) { return res.status(404).json({ error: "No data found" }); } // Struktur der Antwort anpassen const namesMap = results.reduce((map, { idLD, name }) => { if (!map[idLD]) { map[idLD] = name; // Stelle sicher, dass hier keine Duplikate oder Überschreibungen entstehen } return map; }, {}); res.status(200).json(namesMap); } catch (err) { console.error("Fehler beim Abrufen der Daten /device/getAllStationsNames.js :", err); res.status(500).json({ error: "Error retrieving data from the database" }); } finally { if (connection) connection.release(); // Gib die Verbindung zurück in den Pool } }