Merge branch 'feature/dropdown-filter' into develop
This commit is contained in:
32
pages/api/talas_v5_DB/station/getDevices.js
Normal file
32
pages/api/talas_v5_DB/station/getDevices.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// /pages/api/talas_v5_DB/device/getDevices.js
|
||||
import getPool from "../../../../utils/mysqlPool"; // Import Singleton-Pool
|
||||
|
||||
// API-Handler
|
||||
export default async function handler(req, res) {
|
||||
const pool = getPool(); // Singleton-Pool verwenden
|
||||
|
||||
let connection;
|
||||
try {
|
||||
// Lade die Daten der aktiven Systeme aus localStorage, z.B. über einen Parameter oder Body
|
||||
const { activeSystems } = req.body || []; // Array von aktiven system_typ IDs
|
||||
|
||||
// SQL-Query: Verknüpfe die Tabellen location_device, devices und system_typ
|
||||
const sql = `SELECT * FROM devices`;
|
||||
|
||||
connection = await pool.getConnection();
|
||||
|
||||
// Führe die Abfrage mit den aktiven Systems durch
|
||||
const [results] = await connection.query(sql);
|
||||
|
||||
if (!results.length) {
|
||||
return res.status(404).json({ error: "Keine passenden Geräte gefunden" });
|
||||
}
|
||||
|
||||
res.status(200).json(results);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der gefilterten Geräteinformationen:", error);
|
||||
res.status(500).json({ error: "Fehler beim Abrufen der Geräteinformationen" });
|
||||
} finally {
|
||||
if (connection) connection.release();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user