actionCatById.js 846 B

1234567891011121314151617181920212223
  1. import { mock, query } from '../helpers';
  2. import { actionPromise } from '../reducers';
  3. export const actionCatById = ({ _id, promiseName = 'catById', orderBy = '', limit = 20, skip = 0 }) =>
  4. actionPromise(
  5. promiseName,
  6. fetch(`/categories/${_id}/?limit=${limit}&skip=${skip}${orderBy && `&orderBy=` + orderBy}`, {
  7. method: 'GET',
  8. headers: {
  9. 'Content-Type': 'application/json',
  10. Accept: 'application/json',
  11. ...(localStorage.authToken ? { Authorization: 'Bearer ' + localStorage.authToken } : {}),
  12. },
  13. })
  14. .then((res) => res.json())
  15. .then((data) => {
  16. if (data.errors) {
  17. throw new Error(JSON.stringify(data.errors));
  18. } else return data.data;
  19. })
  20. );