idLD geht muss noch das Löschen Button hinzufügen
This commit is contained in:
40
pages/api/getDeviceId.js
Normal file
40
pages/api/getDeviceId.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// API in /api/getDeviceId.js
|
||||
import mysql from "mysql";
|
||||
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method !== "GET") {
|
||||
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
||||
}
|
||||
const { deviceName } = req.query;
|
||||
|
||||
const query = "SELECT idLD FROM location_device WHERE name = ?";
|
||||
connection.query(query, [deviceName], (error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Abrufen der Geräte-ID:", error);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Fehler beim Abrufen der Geräte-ID" });
|
||||
}
|
||||
if (results.length > 0) {
|
||||
res.json({ idLD: results[0].idLD });
|
||||
} else {
|
||||
res.status(404).json({ error: "Gerät nicht gefunden" });
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user