import Common from '../../common/Common';

// 查询授权资源
export const queryAuth = params => {
  const requestUrl = `AuthSettingResource/queryAuthorization?windowNo=${params.windowNo}&recordId=${params.recordId}&userId=${params.userId}`;
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'post',

      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

// 新增授权资源
export const addAuth = params => {
  const requestUrl = `AuthSettingResource/addAuthorization?windowNo=${params.windowNo}&recordId=${params.recordId}&userId=${params.userId}`;
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'post',

      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};