'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createQuizEntryRegrade = createQuizEntryRegrade;

var _constants = require('../../constants');

var _modal = require('../../common/actions/modal');

var _Fetcher = require('../../common/util/Fetcher');

var _Fetcher2 = _interopRequireDefault(_Fetcher);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function createQuizEntryRegrade(quizId, payload) {
  var url = '/api/quizzes/' + quizId + '/quiz_entry_regrades';
  var params = {
    item_id: payload.itemId,
    quiz_entry_id: payload.quizEntryId,
    points_possible: payload.pointsPossible,
    score_reconciliation: payload.scoreReconciliation,
    scoring_algorithm: payload.scoringAlgorithm,
    scoring_data: payload.scoringData
  };
  var body = JSON.stringify({ quiz_entry_regrade: params });

  return function (dispatch, getState) {
    var fetcher = new _Fetcher2.default({
      callType: _constants.CREATE_QUIZ_ENTRY_REGRADE
    });

    var requestParams = { body: body };

    return fetcher.post(url, requestParams).then(function () {
      dispatch((0, _modal.closeModal)(_constants.REGRADE_MODAL));
    });
  };
}