Files
CPLv4.0/redux/thunks/fetchAllTDRChartThunk.ts
Ismail Ali f709c2e3b7 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
2025-04-15 08:55:50 +02:00

36 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// /redux/thunks/fetchAllTDRChartThunk.ts
import { createAsyncThunk } from "@reduxjs/toolkit";
import { RootState } from "../store";
import isEqual from "lodash/isEqual";
import { fetchAllTDRChartDataFromServer } from "../../services/fetchAllTDRChartDataService"; // ✅ importieren
export const fetchAllTDRChartData = createAsyncThunk(
"tdrChart/fetchAllTDRChartData",
async (_, { getState, rejectWithValue }) => {
const state = getState() as RootState;
const currentData = state.tdrChartSlice.data;
const newData = await fetchAllTDRChartDataFromServer(); // ✅ Service aufrufen
if (newData.every((d) => d === null || d === undefined)) {
console.warn("⚠ Keine gültigen Daten empfangen.");
return rejectWithValue("Keine gültigen Daten empfangen.");
}
if (
!isEqual(
JSON.parse(JSON.stringify(currentData)),
JSON.parse(JSON.stringify(newData))
) ||
currentData.length === 0
) {
console.log("🔥 Neue Daten erkannt Redux wird aktualisiert.");
return newData;
} else {
console.log("⚠ Keine signifikanten Änderungen erkannt.");
return rejectWithValue("Keine Änderungen in den Daten.");
}
}
);