{"size": 1078, "ext": "js", "max_stars_repo_path": "src/store/actions/userActions.js", "max_stars_repo_name": "ahmedmusawir/react-redux-starter", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/store/actions/userActions.js", "max_issues_repo_name": "ahmedmusawir/react-redux-starter", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/store/actions/userActions.js", "max_forks_repo_name": "ahmedmusawir/react-redux-starter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.137254902, "max_line_length": 74, "alphanum_fraction": 0.6261595547}
import axios from 'axios';
import { REST_USERS_URL } from './constants';
import {
  GET_USERS, GET_USER, ADD_USER, DELETE_USER, EDIT_USER,
} from './actionTypes';

export const getUsers = () => async (dispatch) => {
  const res = await axios.get(`${REST_USERS_URL}/users`);

  dispatch({
    type: GET_USERS,
    payload: res.data,
  });
};

export const getUser = id => async (dispatch) => {
  const res = await axios.get(`${REST_USERS_URL}/users/${id}`);

  dispatch({
    type: GET_USER,
    payload: res.data,
  });
};

export const addUser = user => async (dispatch) => {
  const res = await axios.post(`${REST_USERS_URL}/users`, user);

  dispatch({
    type: ADD_USER,
    payload: res.data,
  });
};

export const editUser = user => async (dispatch) => {
  const res = await axios.put(`${REST_USERS_URL}/users/${user.id}`, user);

  dispatch({
    type: EDIT_USER,
    payload: res.data,
  });
};

export const deleteUser = id => async (dispatch) => {
  await axios.delete(`${REST_USERS_URL}/users/${id}`);

  dispatch({
    type: DELETE_USER,
    payload: id,
  });
};
