import * as actions from 'lib/redux/actions/sha-actions';
import { get } from 'services/requests';
import { Api } from 'routes/Api';
import { put, call } from 'redux-saga/effects';




export function* fetchSHA(action) {
	try {
		const url = (() => {
			let ret = Api.sha;
			if (action?.specs?.page)
				ret += `/${action?.specs?.page}`;

			if (action?.specs?.code)
				ret += `/${action?.specs?.code}`;
			return ret;
		})();
		const res = yield call(() => get({
			url,
			data: action.specs
		}));

		yield put(actions.fetchedSHA({ data: res.data, id: action?.specs?.id }));
	}
	catch (error) {
		yield put(actions.failedFetchSHA({ specs: action?.specs, error }));
	}
}
