{"size": 1453, "ext": "js", "max_stars_repo_path": "src/Store/Actions/booksActions.js", "max_stars_repo_name": "mark-halls/oer-bookr-web", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Store/Actions/booksActions.js", "max_issues_repo_name": "mark-halls/oer-bookr-web", "max_issues_repo_issues_event_min_datetime": "2022-02-19T06:35:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T10:18:48.000Z", "max_forks_repo_path": "src/Store/Actions/booksActions.js", "max_forks_repo_name": "mark-halls/oer-bookr-web", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 36.325, "max_line_length": 83, "alphanum_fraction": 0.7453544391}
import Axios from "axios"

export const GET_BOOKS_START = 'GET_BOOKS_START'
export const GET_BOOKS_SUCCESS = 'GET_BOOKS_SUCCESS'
export const GET_BOOKS_FAILURE = 'GET_BOOKS_FAILURE'
export const ADD_BOOK_START = 'ADD_BOOK_START'
export const ADD_BOOK_SUCCESS = 'ADD_BOOK_SUCCESS'
export const ADD_BOOK_FAILURE = 'ADD_BOOK_FAILURE'
export const UPDATE_BOOK_START = 'UPDATE_BOOK_START'
export const UPDATE_BOOK_SUCCESS = 'UPDATE_BOOK_SUCCESS'
export const UPDATE_BOOK_FAILURE = 'UPDATE_BOOK_FAILURE'
export const DELETE_BOOK_START = 'DELETE_BOOK_START'
export const DELETE_BOOK_SUCCESS = 'DELETE_BOOK_SUCCESS'
export const DELETE_BOOK_FAILURE = 'DELETE_BOOK_FAILURE'

const BASE_URL = "https://samirlilienfeld-oer-bookr.herokuapp.com/"

const token = localStorage.getItem("token");
const requestOptions = {
  headers: {
    authorization: token
  }
}

export const getBooks = () => dispatch => {
  dispatch({ type: GET_BOOKS_START })
  Axios
    .get(`${BASE_URL}/books/books/paging`, requestOptions)
    .then(res => {
      dispatch({ type: GET_BOOKS_SUCCESS, payload: res.data })
    })
    .catch(err => dispatch({ type: GET_BOOKS_FAILURE, payload: err }))
}

export const deleteBook = id => dispatch => {
  dispatch({ type: DELETE_BOOK_START })
  Axios.delete(`${BASE_URL}/data/books/${id}`)
    .then(res => { dispatch({ type: DELETE_BOOK_SUCCESS, payload: res.data.id }) })
    .catch(err => dispatch({ type: DELETE_BOOK_FAILURE, payload: err }))
}