import * as actions from 'lib/redux/actions/humans-actions';
import { Action } from 'lib/types/interfaces';
import { get } from 'services/requests';
import { Api } from 'routes/Api';
import { call, put } from 'redux-saga/effects';

export function* fetchHumans() {
	try {
		const res = yield call(() => get({
			url: Api.humans,
		}));

		yield put(actions.fetchedHumans({ data: res.data }));
	}
	catch (error) {
		yield put(actions.failedFetchHumans({ error }));
	}
}


export function* fetchHuman(action: Action) {
	try {
		const res = yield call(() => get({
			url: action?.except_url ? Api.humans + '/' + action?.except_url : Api.humans,
		}));

		yield put(actions.fetchedHuman({ data: res.data }));
	}
	catch (error) {
		yield put(actions.failedFetchHuman({ error }));
	}
}