Browse Source

redux tooki 비행이력 thunk type 수정

master
박상현 7 months ago
parent
commit
f1edab0f55
  1. 17
      src/_redux/features/analysis/history/historySlice.ts
  2. 38
      src/_redux/features/analysis/history/historyThunk.ts
  3. 12
      src/_redux/features/analysis/simulation/simulationSlice.ts
  4. 44
      src/_redux/features/analysis/simulation/simulationThunk.ts

17
src/_redux/features/analysis/history/historySlice.ts

@ -50,16 +50,15 @@ const historySlice = createSlice({
}
},
extraReducers: builder => {
// builder.addCase(getHstryList., (state, action) => {
// const { searchParams, page } = action.payload;
// state.searchParams = searchParams;
// state.page = page;
// }
// );
builder.addCase(getHstryList.fulfilled, (state, action) => {
state.data = action.payload.items as IGetHstryListRs[];
state.count = action.payload.page as number;
state.total = action.payload.total as number;
const { items, page, total } = action.payload as {
items: IGetHstryListRs[];
page: number;
total: number;
};
state.data = items as IGetHstryListRs[];
state.count = page as number;
state.total = total as number;
});
builder.addCase(getHstryLog.fulfilled, (state, action) => {
state.log = action.payload as IGetHstryLogRs[];

38
src/_redux/features/analysis/history/historyThunk.ts

@ -3,20 +3,32 @@ import qs from 'qs';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { openModal } from '../../comn/message/messageSlice';
import { QS_OPTION } from '@src/configs/constants';
import { IHstryListRq } from './historyState';
import {
IGetHstryDetailRs,
IGetHstryListRs,
IGetHstryLogRs,
IHstryListRq
} from './historyState';
import { MODAL_BODY, MODAL_HEADER } from '@src/configs/msgConst';
// 비행이력 조회
export const getHstryList = createAsyncThunk(
'analysis/getHstryList',
async (data: IHstryListRq, thunkAPI) => {
async (rq: IHstryListRq, thunkAPI) => {
try {
const queryString = qs.stringify(data.searchParams, QS_OPTION);
const res: any = await axios.get(
`/api/anls/hstry/list${queryString}&page=${data.page}`
);
const queryString = qs.stringify(rq.searchParams, QS_OPTION);
const {
data
}: {
data: {
items: IGetHstryListRs[];
page: number;
total: number;
errorCode?: string;
};
} = await axios.get(`/api/anls/hstry/list${queryString}&page=${rq.page}`);
return res.data;
return data;
} catch (error) {
thunkAPI.dispatch(
openModal({
@ -33,8 +45,10 @@ export const getHstryLog = createAsyncThunk(
'analysis/getHstryLog',
async (id: string, thunkAPI) => {
try {
const res: any = await axios.get(`/api/anls/hstry/log/${id}`);
return res.data;
const { data }: { data: IGetHstryLogRs[] } = await axios.get(
`/api/anls/hstry/log/${id}`
);
return data;
} catch (error) {
thunkAPI.dispatch(
openModal({
@ -51,8 +65,10 @@ export const getHstryDetail = createAsyncThunk(
'analysis/getHstryDetail',
async (id: string, thunkAPI) => {
try {
const res: any = await axios.get(`/api/anls/hstry/detail/${id}`);
return res.data;
const { data }: { data: IGetHstryDetailRs } = await axios.get(
`/api/anls/hstry/detail/${id}`
);
return data;
} catch (error) {
thunkAPI.dispatch(
openModal({

12
src/_redux/features/analysis/simulation/simulationSlice.ts

@ -54,7 +54,13 @@ const simulationSlice = createSlice({
},
extraReducers: builder => {
builder.addCase(getSmltList.fulfilled, (state, action) => {
const { items, count, total, page } = action.payload;
const { items, count, total, page } = action.payload as {
items: IAnalysisSimulatorRs[];
count: number;
total: number;
page: number;
};
if (!state.list) {
state.list = items;
} else {
@ -74,10 +80,10 @@ const simulationSlice = createSlice({
});
builder.addCase(getSmltStcs.fulfilled, (state, action) => {
state.stcsList = action.payload as IAnalysisSimulatorStcsRs[];
state.stcsCount = action.payload.length as number;
state.stcsCount = action.payload?.length as number;
});
builder.addCase(getSmltLog.fulfilled, (state, action) => {
const data = action.payload.sort((p: any, n: any): any => {
const data = action.payload?.sort((p: any, n: any): any => {
const a = p.srvrRcvDt.replace(/[^0-9\.]+/g, '');
const b = n.srvrRcvDt.replace(/[^0-9\.]+/g, '');
return a - b;

44
src/_redux/features/analysis/simulation/simulationThunk.ts

@ -3,20 +3,32 @@ import qs from 'qs';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { openModal } from '../../comn/message/messageSlice';
import { QS_OPTION } from '@src/configs/constants';
import { IAnalysisSimulatorListRq } from './simulationState';
import {
IAnalysisSimulatorListRq,
IAnalysisSimulatorLogRs,
IAnalysisSimulatorRs,
IAnalysisSimulatorStcsRs
} from './simulationState';
import { MODAL_BODY, MODAL_HEADER } from '@src/configs/msgConst';
// 비행 현황 목록
export const getSmltList = createAsyncThunk(
'analysis/getSmltList',
async (data: IAnalysisSimulatorListRq, thunkAPI) => {
async (rq: IAnalysisSimulatorListRq, thunkAPI) => {
try {
const queryString = qs.stringify(data.searchParams, QS_OPTION);
const res: any = await axios.get(
`/api/anls/smlt/list${queryString}&page=${data.page}`
);
const queryString = qs.stringify(rq.searchParams, QS_OPTION);
const {
data
}: {
data: {
items: IAnalysisSimulatorRs[];
count: number;
total: number;
page: number;
};
} = await axios.get(`/api/anls/smlt/list${queryString}&page=${rq.page}`);
return res.data;
return data;
} catch (error) {
thunkAPI.dispatch(
openModal({
@ -33,8 +45,10 @@ export const getSmltLog = createAsyncThunk(
'analysis/getSmltLog',
async (id: string, thunkAPI) => {
try {
const res: any = await axios.get(`/api/anls/smlt/hist/${id}`);
return res.data;
const { data }: { data: IAnalysisSimulatorLogRs[] } = await axios.get(
`/api/anls/smlt/hist/${id}`
);
return data;
} catch (error) {
thunkAPI.dispatch(
openModal({
@ -51,8 +65,10 @@ export const getSmltDetail = createAsyncThunk(
'analysis/getSmltDetail',
async (id: string, thunkAPI) => {
try {
const res: any = await axios.get(`/api/anls/smlt/detail/${id}`);
return res.data;
const { data }: { data: IAnalysisSimulatorRs } = await axios.get(
`/api/anls/smlt/detail/${id}`
);
return data;
} catch (error) {
thunkAPI.dispatch(
openModal({
@ -69,8 +85,10 @@ export const getSmltStcs = createAsyncThunk(
'analysis/getSmltStcs',
async (id: string, thunkAPI) => {
try {
const res: any = await axios.get(`/api/anls/smlt/stcs/${id}`);
return res.data;
const { data }: { data: IAnalysisSimulatorStcsRs[] } = await axios.get(
`/api/anls/smlt/stcs/${id}`
);
return data;
} catch (error) {
thunkAPI.dispatch(
openModal({

Loading…
Cancel
Save