@omegabigdata/honoplay-redux-helper
Version:
honoplay-redux-helper
101 lines (92 loc) • 2.52 kB
JavaScript
import {
FETCHING_TRAINEE_LIST,
FETCH_TRAINEE_LIST_SUCCESS,
FETCH_TRAINEE_LIST_FAILED,
FETCHING_TRAINEE,
FETCH_TRAINEE_SUCCESS,
FETCH_TRAINEE_FAILED,
UPDATING_TRAINEE,
UPDATE_TRAINEE_SUCCESS,
UPDATE_TRAINEE_FAILED,
CREATING_TRAINEE,
CREATE_TRAINEE_SUCCESS,
CREATE_TRAINEE_FAILED,
FETCHING_TRAINEEUSER_BY_CLASSROOMID,
FETCH_TRAINEEUSER_BY_CLASSROOMID_SUCCESS,
FETCH_TRAINEEUSER_BY_CLASSROOMID_FAILED
} from '../helpers/ActionTypes/Trainee';
import { Trainee } from '@omegabigdata/honoplay-api-helper-node';
const fetchTraineeUserByClassroomId = classroomId => dispatch => {
dispatch({ type: FETCHING_TRAINEEUSER_BY_CLASSROOMID });
Trainee.getTraineeUserByClassroomId(
classroomId,
success => {
dispatch({
type: FETCH_TRAINEEUSER_BY_CLASSROOMID_SUCCESS,
data: success.data
});
},
error => {
dispatch({
type: FETCH_TRAINEEUSER_BY_CLASSROOMID_FAILED,
data: { error }
});
}
);
};
const fetchTraineeList = (skip = null, take = null) => dispatch => {
dispatch({ type: FETCHING_TRAINEE_LIST });
Trainee.getTrainees(
skip,
take,
success => {
dispatch({ type: FETCH_TRAINEE_LIST_SUCCESS, data: success.data });
},
error => {
dispatch({ type: FETCH_TRAINEE_LIST_FAILED, data: { error } });
}
);
};
const fetchTrainee = traineeId => dispatch => {
dispatch({ type: FETCHING_TRAINEE });
Trainee.getTrainee(
traineeId,
success => {
dispatch({ type: FETCH_TRAINEE_SUCCESS, data: success.data });
},
error => {
dispatch({ type: FETCH_TRAINEE_FAILED, data: { error } });
}
);
};
const createTrainee = traineeModel => dispatch => {
dispatch({ type: CREATING_TRAINEE });
Trainee.postTrainee(
traineeModel,
success => {
dispatch({ type: CREATE_TRAINEE_SUCCESS, data: success.data });
},
error => {
dispatch({ type: CREATE_TRAINEE_FAILED, data: { error } });
}
);
};
const updateTrainee = traineeModel => dispatch => {
dispatch({ type: UPDATING_TRAINEE });
Trainee.putTrainee(
traineeModel,
success => {
dispatch({ type: UPDATE_TRAINEE_SUCCESS, data: success.data });
},
error => {
dispatch({ type: UPDATE_TRAINEE_FAILED, data: { error } });
}
);
};
export {
fetchTraineeList,
fetchTrainee,
createTrainee,
updateTrainee,
fetchTraineeUserByClassroomId
};