"use strict";

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

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

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

var _callHandlers = require("../../common/api/callHandlers");

var _reporting = require("../../common/actions/reporting");

var _quizzes = require("../../common/actions/quizzes");

function getQuizAnalysis(quizId) {
  var url = "/api/quizzes/".concat(quizId, "/stats/quiz_analysis");
  return function (dispatch, getState) {
    var fetcher = new _Fetcher.default({
      onError: function onError() {
        return (0, _reporting.markQuizAnalysisNotFound)(quizId);
      }
    });
    return fetcher.get(url).then(function (response) {
      dispatch([(0, _callHandlers.handleQuizAnalysisResponse)(response), (0, _quizzes.associateQuizAnalysis)(quizId, response)]);
    });
  };
}