All files / sagas EventSaga.js

0% Statements 0/49
0% Branches 0/17
0% Functions 0/6
0% Lines 0/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                                                                           
import { takeEvery, put, call } from 'redux-saga/effects';
import { REQUEST_EVENTS, RECEIVE_EVENTS } from '../actionTypes';
 
export function* fetchEvents(action) {
  try {
    const response = yield call(
      action.Api.getEvents,
      action.requestParms,
      action.numDaysPast,
      action.includeEvents,
    );
    yield put({ type: RECEIVE_EVENTS, response, status: 'success' });
  } catch (error) {
    yield put({ type: RECEIVE_EVENTS, response: error, status: 'error' });
  }
}
 
export function* changeReadStatus(action) {
  try {
    yield put({ type: 'CHANGE_READ_STATUS', status: 'started' });
    const response = yield call(
      action.changeReadStatus,
      action.requestParms,
      action.id,
      action.status,
      action.numDaysPast,
    );
    yield put({ type: 'CHANGE_READ_STATUS', response, status: 'finished' });
  } catch (error) {
    yield put({ type: 'CHANGE_READ_STATUS', response: error, status: 'error' });
  }
}
 
export default function* EventSaga() {
  yield takeEvery(REQUEST_EVENTS, fetchEvents);
  yield takeEvery('CHANGE_READ_STATUS', changeReadStatus);
}