36 lines
944 B
TypeScript
36 lines
944 B
TypeScript
// /redux/thunks/getLoopChartDataThunk.ts
|
|
import { createAsyncThunk } from "@reduxjs/toolkit";
|
|
import { fetchLoopChartData } from "@/services/fetchLoopChartDataService";
|
|
|
|
interface FetchLoopChartDataParams {
|
|
mode: "DIA0" | "DIA1" | "DIA2";
|
|
type: number;
|
|
slotNumber: number;
|
|
vonDatum: string;
|
|
bisDatum: string;
|
|
}
|
|
|
|
export const getLoopChartDataThunk = createAsyncThunk(
|
|
"loopChart/fetchLoopChartData",
|
|
async (params: FetchLoopChartDataParams, { rejectWithValue }) => {
|
|
try {
|
|
const data = await fetchLoopChartData(
|
|
params.mode,
|
|
params.type,
|
|
params.slotNumber,
|
|
params.vonDatum,
|
|
params.bisDatum
|
|
);
|
|
|
|
if (!data) {
|
|
return rejectWithValue("Keine Daten erhalten");
|
|
}
|
|
|
|
return data;
|
|
} catch (error: any) {
|
|
console.error("❌ Fehler in getLoopChartDataThunk:", error);
|
|
return rejectWithValue(error.message || "Unbekannter Fehler");
|
|
}
|
|
}
|
|
);
|