deleteQuestion.js 818 B

12345678910111213141516171819202122232425262728
  1. import { put, call } from 'redux-saga/effects';
  2. import axios from 'axios';
  3. import { CREATE_QUESTIONS } from '../../../constants/admin';
  4. import { deleteQuestionSuccess, deleteQuestionFailure } from '../../../actions/admin/changeTest/deleteQuestion';
  5. import storageKey from '../../../utils/storageKey';
  6. const getItem = localStorage.getItem(storageKey);
  7. export default function* ({ payload: { questionId } }) {
  8. try {
  9. const config = {
  10. headers: {
  11. "Authorization": `Bearer ${getItem}`
  12. }
  13. }
  14. const question = yield call(() =>
  15. axios.delete(`${CREATE_QUESTIONS}${'/'}${questionId}`, config)
  16. )
  17. yield put(deleteQuestionSuccess(question));
  18. }
  19. catch ({ message }) {
  20. yield put(deleteQuestionFailure(message));
  21. }
  22. }