2020-02-19 11:53:32 +01:00
|
|
|
import { call, put } from 'redux-saga/effects';
|
|
|
|
import { projectUserListFailure, projectUserListSuccess, projectListFailure, projectListSuccess } from '../actions/project';
|
|
|
|
|
|
|
|
export function* projectUserListSaga() {
|
2020-03-09 14:49:56 +01:00
|
|
|
let result;
|
2020-02-19 11:53:32 +01:00
|
|
|
try {
|
|
|
|
result = yield call(projectUserList);
|
|
|
|
} catch(err) {
|
|
|
|
yield put(projectUserListFailure(err));
|
2020-03-09 14:49:56 +01:00
|
|
|
return;
|
2020-02-19 11:53:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ('error' in result) {
|
|
|
|
yield put(projectUserListFailure(result.error));
|
2020-03-09 14:49:56 +01:00
|
|
|
return;
|
2020-02-19 11:53:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
yield put(projectUserListSuccess(result.data));
|
|
|
|
}
|
|
|
|
|
|
|
|
const projectUserList = () => {
|
|
|
|
return fetch('http://localhost:8001/api/v1/me', {
|
|
|
|
method: 'GET',
|
|
|
|
mode: 'cors',
|
|
|
|
credentials: 'include'
|
2020-03-09 14:49:56 +01:00
|
|
|
}).then(res => res.json());
|
|
|
|
};
|
2020-02-19 11:53:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
export function* projectListSaga() {
|
2020-03-09 14:49:56 +01:00
|
|
|
let result;
|
2020-02-19 11:53:32 +01:00
|
|
|
try {
|
|
|
|
result = yield call(projectList);
|
|
|
|
} catch(err) {
|
|
|
|
yield put(projectListFailure(err));
|
2020-03-09 14:49:56 +01:00
|
|
|
return;
|
2020-02-19 11:53:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ('error' in result) {
|
|
|
|
yield put(projectListFailure(result.error));
|
2020-03-09 14:49:56 +01:00
|
|
|
return;
|
2020-02-19 11:53:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
yield put(projectListSuccess(result.data));
|
|
|
|
}
|
|
|
|
|
|
|
|
const projectList = () => {
|
|
|
|
return fetch('http://localhost:8001/api/v1/projects', {
|
|
|
|
method: 'GET',
|
|
|
|
mode: 'cors',
|
|
|
|
credentials: 'include'
|
2020-03-09 14:49:56 +01:00
|
|
|
}).then(res => res.json());
|
|
|
|
};
|