"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _constants = require("@instructure/quiz-common/lib/constants");

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

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

function createQuizEntryRegrade(quizId, payload) {
  var url = "/api/quizzes/".concat(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 _Fetcher.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));
    });
  };
}