refactor: Naming-Konventionen für digitaleEingaenge umgesetzt
- digitaleEingaengeMockData.js = strukturierte Datenbasis für Development - digitaleEingaengeAPIHandler.ts = API-Endpunkt zur Auslieferung im Dev - fetchDigitaleEingaengeService.ts = Service zur Umwandlung von window-Variablen - Naming-Schema sorgt für klare Struktur und gute Lernbarkeit
This commit is contained in:
27
services/fetchTDRReferenceCurveService.ts
Normal file
27
services/fetchTDRReferenceCurveService.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// /services/fetchTDRReferenceCurveService.ts
|
||||
|
||||
export const fetchTDRReferenceCurve = async (
|
||||
slot: number
|
||||
): Promise<any[] | null> => {
|
||||
// ✅ Erst aus localStorage lesen
|
||||
const local = localStorage.getItem(`ref-curve-slot${slot}`);
|
||||
if (local) {
|
||||
console.log(`📦 Lade Referenzkurve für Slot ${slot} aus localStorage`);
|
||||
return JSON.parse(local);
|
||||
}
|
||||
|
||||
// 🔁 Fallback: Datei oder Produktion-API
|
||||
const isDev = process.env.NEXT_PUBLIC_NODE_ENV === "development";
|
||||
const url = isDev
|
||||
? `/apiMockData/tdr-reference-curves/slot${slot}.json`
|
||||
: `${window.location.origin}/CPL?Service/empty.acp&TDR=${slot}`;
|
||||
|
||||
try {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
return await res.json();
|
||||
} catch (error) {
|
||||
console.error(`❌ Fehler beim Laden von Slot ${slot}:`, error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user