feat: handleSave final auf API-Handler für Development erweitert
- Änderungen in Dev-Umgebung werden per /api/cpl/updateKueDataAPIHandler gespeichert - Production weiterhin GET-Request mit Parametern - Fehlerbehandlung optimiert
This commit is contained in:
52
pages/api/cpl/updateKueDataAPIHandler.ts
Normal file
52
pages/api/cpl/updateKueDataAPIHandler.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
// /pages/api/cpl/updateKueDataAPIHandler.ts
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
if (req.method !== "POST") {
|
||||
return res.status(405).json({ error: "Method not allowed" });
|
||||
}
|
||||
|
||||
const { data } = req.body;
|
||||
|
||||
if (!data) {
|
||||
return res.status(400).json({ error: "No data provided" });
|
||||
}
|
||||
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"kueDataMockData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
const fileContent =
|
||||
`window.win_kueID = ${JSON.stringify(data.kueID)};\n` +
|
||||
`window.win_kuePSTmMinus96V = ${JSON.stringify(
|
||||
data.kueBezeichnungen
|
||||
)};\n` +
|
||||
`window.win_kueLimit1 = ${JSON.stringify(data.isolationsgrenzwerte)};\n` +
|
||||
`window.win_kueDelay1 = ${JSON.stringify(data.verzoegerung)};\n` +
|
||||
`window.win_kueLimit2Low = ${JSON.stringify(
|
||||
data.untereSchleifenGrenzwerte
|
||||
)};\n` +
|
||||
`window.win_kueLimit2High = ${JSON.stringify(
|
||||
data.obereSchleifenGrenzwerte
|
||||
)};\n` +
|
||||
`window.win_kueLoopInterval = ${JSON.stringify(
|
||||
data.schleifenintervall
|
||||
)};\n`;
|
||||
|
||||
await fs.writeFile(filePath, fileContent, "utf-8");
|
||||
|
||||
res.status(200).json({ success: true });
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Schreiben der Datei:", error);
|
||||
res.status(500).json({ error: "Failed to write file" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user