You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

filesSaga.js 1.1KB

12345678910111213141516171819202122232425262728
  1. import { all, call, put, takeEvery } from "redux-saga/effects";
  2. import { JWT_TOKEN } from "../../constants/localStorage";
  3. import { addHeaderToken } from "../../request";
  4. import { getAllFilesReq } from "../../request/fileRequests";
  5. import { authScopeStringGetHelper } from "../../util/helpers/authScopeHelpers";
  6. import { rejectErrorCodeHelper } from "../../util/helpers/rejectErrorCodeHelper";
  7. import { FETCH_FILES_REQ } from "../actions/files/fileActionConstants";
  8. import {
  9. getFileError,
  10. getFileSuccess,
  11. } from "../actions/files/fileActions";
  12. export function* getAll() {
  13. try {
  14. const JwtToken = yield call(authScopeStringGetHelper, JWT_TOKEN);
  15. yield call(addHeaderToken, JwtToken);
  16. const result = yield call(getAllFilesReq);
  17. yield put(getFileSuccess(result.data));
  18. } catch (error) {
  19. if (error.response && error.response.data) {
  20. const errorMessage = yield call(rejectErrorCodeHelper, error);
  21. yield put(getFileError(errorMessage));
  22. }
  23. }
  24. }
  25. export default function* filesSaga() {
  26. yield all([takeEvery(FETCH_FILES_REQ, getAll)]);
  27. }