Stationnamen sind richtig
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// /pages/api/talas_v5_DB/station/getStationNameByIdLD.js
|
||||
// /pages/api/talas_v5_DB/station/getAllStationsNames.js
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
// Verbindungspool-Konfiguration
|
||||
@@ -20,10 +20,22 @@ export default async function handler(req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
// Verwenden des Verbindungspools, um die Abfrage auszuführen
|
||||
const [results] = await pool.query("SELECT * FROM location_device");
|
||||
// Abrufen aller idLD und ihrer Namen
|
||||
const [results] = await pool.query("SELECT idLD, name FROM location_device");
|
||||
|
||||
res.status(200).json(results);
|
||||
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:", err);
|
||||
res.status(500).json({ error: "Error retrieving data from the database" });
|
||||
Reference in New Issue
Block a user