Merge branch 'feature/dropdown-filter' into develop

This commit is contained in:
ISA
2024-10-02 06:59:24 +02:00
9 changed files with 310 additions and 66 deletions

View File

@@ -7,25 +7,27 @@ export default async function handler(req, res) {
let connection;
try {
// SQL-Query and parameters
const sql = "SELECT idLD, iddevice, name FROM location_device WHERE iddevice = ?";
const params = [160]; // Example parameter
// SQL-Query, um die Geräteinformationen aus location_device und devices zu erhalten
const sql = `
SELECT ld.idLD, ld.iddevice, ld.name, d.idsystem_typ
FROM location_device ld
JOIN devices d ON ld.iddevice = d.iddevice
ORDER BY ld.name
`;
// Get a connection from the pool
connection = await pool.getConnection();
// Execute the query
const [results] = await connection.query(sql, params);
// Führe die Abfrage durch
const [results] = await connection.query(sql);
// Check if results are empty
if (!results.length) {
return res.status(404).json({ error: "Keine Geräte gefunden" });
}
// Respond with the results
// Geben Sie die Daten zurück
res.status(200).json(results);
} catch (error) {
// Log and return error
// Loggen Sie den Fehler und geben Sie ihn zurück
console.error("Fehler beim Abrufen der Geräteinformationen:", error);
res.status(500).json({ error: "Fehler beim Abrufen der Geräteinformationen" });
} finally {

View 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();
}
}