2018-04-23 05:04:09 +00:00
|
|
|
import { effects } from "redux-saga";
|
|
|
|
import {
|
|
|
|
isSendingPShiftRequest,
|
|
|
|
setPShiftRequestError,
|
|
|
|
setPShiftRequestSuccess,
|
|
|
|
clearPShiftRequestError,
|
|
|
|
clearPShiftRequestSuccess
|
|
|
|
} from "../actions/pShift/reducer.actions";
|
2018-04-23 17:07:33 +00:00
|
|
|
import { getPShifts, getPShift, updatePShift } from "../api/pShift.api";
|
|
|
|
import {
|
|
|
|
getPShiftsRequest,
|
|
|
|
getPShiftRequest
|
|
|
|
} from "../actions/pShift/saga.actions";
|
2018-04-23 05:04:09 +00:00
|
|
|
|
|
|
|
function* getPShiftsCall(params) {
|
|
|
|
yield effects.put(isSendingPShiftRequest(true));
|
|
|
|
try {
|
|
|
|
return yield effects.call(getPShifts, params);
|
|
|
|
} catch (exception) {
|
|
|
|
yield effects.put(setPShiftRequestError(exception));
|
|
|
|
return false;
|
|
|
|
} finally {
|
|
|
|
yield effects.put(isSendingPShiftRequest(false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 17:07:33 +00:00
|
|
|
function* getPShiftCall(payload) {
|
|
|
|
yield effects.put(isSendingPShiftRequest(true));
|
|
|
|
try {
|
|
|
|
return yield effects.call(getPShift, payload.uuid);
|
|
|
|
} catch (exception) {
|
|
|
|
yield effects.put(setPShiftRequestError(exception));
|
|
|
|
return false;
|
|
|
|
} finally {
|
|
|
|
yield effects.put(isSendingPShiftRequest(false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function* updatePShiftCall(payload) {
|
|
|
|
yield effects.put(isSendingPShiftRequest(true));
|
|
|
|
try {
|
|
|
|
return yield effects.call(updatePShift, payload.uuid, payload);
|
|
|
|
} catch (exception) {
|
|
|
|
yield effects.put(setPShiftRequestError(exception));
|
|
|
|
return false;
|
|
|
|
} finally {
|
|
|
|
yield effects.put(isSendingPShiftRequest(false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 05:04:09 +00:00
|
|
|
export function* getPShiftsFlow(request) {
|
|
|
|
yield effects.put(clearPShiftRequestSuccess());
|
|
|
|
yield effects.put(clearPShiftRequestError());
|
|
|
|
const wasSuccessful = yield effects.call(getPShiftsCall, request.data);
|
|
|
|
if (wasSuccessful) {
|
|
|
|
yield effects.put(setPShiftRequestSuccess(wasSuccessful));
|
|
|
|
}
|
|
|
|
}
|
2018-04-23 17:07:33 +00:00
|
|
|
|
|
|
|
export function* getPShiftFlow(request) {
|
|
|
|
yield effects.put(clearPShiftRequestSuccess());
|
|
|
|
yield effects.put(clearPShiftRequestError());
|
|
|
|
const wasSuccessful = yield effects.call(getPShiftCall, request.data);
|
|
|
|
if (wasSuccessful) {
|
|
|
|
yield effects.put(setPShiftRequestSuccess(wasSuccessful));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* updatePShiftFlow(request) {
|
2018-04-23 18:19:14 +00:00
|
|
|
if (!request.data.single) {
|
|
|
|
yield effects.put(clearPShiftRequestSuccess());
|
|
|
|
}
|
2018-04-23 17:07:33 +00:00
|
|
|
yield effects.put(clearPShiftRequestError());
|
|
|
|
const wasSuccessful = yield effects.call(updatePShiftCall, request.data);
|
|
|
|
if (wasSuccessful) {
|
|
|
|
yield effects.put(setPShiftRequestSuccess(wasSuccessful));
|
|
|
|
if (request.data.single) {
|
|
|
|
yield effects.put(getPShiftRequest({ uuid: request.data.uuid }));
|
|
|
|
} else {
|
|
|
|
yield effects.put(getPShiftsRequest({ page: 1 }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|