"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.updateProgressDesc = exports.updateProgress = exports.remindAction = exports.getRelProgress = exports.getProgress = exports.getOkrDetail = void 0;

var _qs = _interopRequireDefault(require("qs"));

var _getLocale = require("../../utils/getLocale");

var _request = require("../../utils/request");

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var getRelProgress = function getRelProgress(workId) {
  return (0, _request.rget)("v1")("okr/detail/relProgress?okrId=".concat(workId));
};

exports.getRelProgress = getRelProgress;

var getProgress = function getProgress(workId) {
  return (0, _request.rget)("v1")("Work/GetProgress?work_id=".concat(workId, "&count=10000"));
};

exports.getProgress = getProgress;

var updateProgressDesc = function updateProgressDesc(commentId, workId, content) {
  return (0, _request.rpost)("v1")("progress/updateContent?commentId=".concat(commentId, "&objId=").concat(workId, "&objType=62"), {
    content: content
  });
}; // type: 1 上级查看 2 更新


exports.updateProgressDesc = updateProgressDesc;

var remindAction = function remindAction(_ref) {
  var toUserId = _ref.toUserId,
      work_id = _ref.work_id,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 1 : _ref$type;
  return (0, _request.rpost)("v1")("work/notify/message?toUserId=".concat(toUserId), {
    objId: work_id,
    content: "",
    toUserId: toUserId,
    templateId: type === 1 ? "TitaFeedSystem.Work.Okr.Message.RemindSuperiorLookOkrInfo" : "TitaFeedSystem.Work.Okr.Message.RemindSubUpdateProgress"
  }, {
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.remindAction = remindAction;

var updateProgress = function updateProgress(params) {
  return (0, _request.rpost)("v2")("Work/progress", _objectSpread({}, params));
};

exports.updateProgress = updateProgress;

var getOkrDetail = function getOkrDetail(_ref2) {
  var okrId = _ref2.okrId;
  return (0, _request.rget)("v1")("okr/detailInfo?okrId=".concat(okrId)).then(function (headInfo) {
    if (headInfo.Code != 1) {
      throw headInfo.Message.replace(/项目/g, (0, _getLocale.getLocale)("Mod_Objective"));
    }

    return headInfo.Data;
  });
};

exports.getOkrDetail = getOkrDetail;