UNPKG

@omegabigdata/honoplay-redux-helper

Version:
72 lines (65 loc) 1.87 kB
import { CREATE_TRAINER_FAILED, CREATE_TRAINER_SUCCESS, CREATING_TRAINER, FETCHING_TRAINER, FETCHING_TRAINER_LIST, FETCH_TRAINER_FAILED, FETCH_TRAINER_LIST_FAILED, FETCH_TRAINER_LIST_SUCCESS, FETCH_TRAINER_SUCCESS, UPDATE_TRAINER_FAILED, UPDATE_TRAINER_SUCCESS, UPDATING_TRAINER } from "../helpers/ActionTypes/Trainer"; import { Trainer } from "@omegabigdata/honoplay-api-helper-node"; const fetchTrainersList = (skip = null, take = null) => dispatch => { dispatch({ type: FETCHING_TRAINER_LIST }); Trainer.getTrainers( skip, take, success => { dispatch({ type: FETCH_TRAINER_LIST_SUCCESS, data: success.data }); }, error => { dispatch({ type: FETCH_TRAINER_LIST_FAILED, data: { error } }); } ); }; const fetchTrainer = trainerId => dispatch => { dispatch({ type: FETCHING_TRAINER }); Trainer.getTrainer( trainerId, success => { dispatch({ type: FETCH_TRAINER_SUCCESS, data: success.data }); }, error => { dispatch({ type: FETCH_TRAINER_FAILED, data: { error } }); } ); }; const createTrainer = trainerModel => dispatch => { dispatch({ type: CREATING_TRAINER }); Trainer.postTrainer( trainerModel, success => { dispatch({ type: CREATE_TRAINER_SUCCESS, data: success.data }); }, error => { dispatch({ type: CREATE_TRAINER_FAILED, data: { error } }); } ); }; const updateTrainer = trainerModel => dispatch => { dispatch({ type: UPDATING_TRAINER }); Trainer.putTrainer( trainerModel, success => { dispatch({ type: UPDATE_TRAINER_SUCCESS, data: success.data }); }, error => { dispatch({ type: UPDATE_TRAINER_FAILED, data: { error } }); } ); }; export { fetchTrainersList, fetchTrainer, createTrainer, updateTrainer };