github.com/outbrain/consul@v1.4.5/ui-v2/app/adapters/session.js (about)

     1  import Adapter, {
     2    REQUEST_DELETE,
     3    DATACENTER_QUERY_PARAM as API_DATACENTER_KEY,
     4  } from './application';
     5  
     6  import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc';
     7  import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/session';
     8  import { PUT as HTTP_PUT } from 'consul-ui/utils/http/method';
     9  import { OK as HTTP_OK } from 'consul-ui/utils/http/status';
    10  
    11  export default Adapter.extend({
    12    urlForQuery: function(query, modelName) {
    13      if (typeof query.id === 'undefined') {
    14        throw new Error('You must specify an id');
    15      }
    16      return this.appendURL('session/node', [query.id], this.cleanQuery(query));
    17    },
    18    urlForQueryRecord: function(query, modelName) {
    19      if (typeof query.id === 'undefined') {
    20        throw new Error('You must specify an id');
    21      }
    22      return this.appendURL('session/info', [query.id], this.cleanQuery(query));
    23    },
    24    urlForDeleteRecord: function(id, modelName, snapshot) {
    25      const query = {
    26        [API_DATACENTER_KEY]: snapshot.attr(DATACENTER_KEY),
    27      };
    28      return this.appendURL('session/destroy', [snapshot.attr(SLUG_KEY)], query);
    29    },
    30    methodForRequest: function(params) {
    31      switch (params.requestType) {
    32        case REQUEST_DELETE:
    33          return HTTP_PUT;
    34      }
    35      return this._super(...arguments);
    36    },
    37    handleResponse: function(status, headers, payload, requestData) {
    38      let response = payload;
    39      const method = requestData.method;
    40      if (status === HTTP_OK) {
    41        const url = this.parseURL(requestData.url);
    42        switch (true) {
    43          case response === true:
    44            response = this.handleBooleanResponse(url, response, PRIMARY_KEY, SLUG_KEY);
    45            break;
    46          case this.isQueryRecord(url, method):
    47            response = this.handleSingleResponse(url, response[0], PRIMARY_KEY, SLUG_KEY);
    48            break;
    49          default:
    50            response = this.handleBatchResponse(url, response, PRIMARY_KEY, SLUG_KEY);
    51        }
    52      }
    53      return this._super(status, headers, response, requestData);
    54    },
    55  });