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

     1  import Adapter from './application';
     2  import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service';
     3  import { OK as HTTP_OK } from 'consul-ui/utils/http/status';
     4  const URL_PREFIX_SINGLE = 'health/service';
     5  const URL_PREFIX_MULTIPLE = 'internal/ui/services';
     6  export default Adapter.extend({
     7    urlForQuery: function(query, modelName) {
     8      return this.appendURL(URL_PREFIX_MULTIPLE, [], this.cleanQuery(query));
     9    },
    10    urlForQueryRecord: function(query, modelName) {
    11      if (typeof query.id === 'undefined') {
    12        throw new Error('You must specify an id');
    13      }
    14      return this.appendURL(URL_PREFIX_SINGLE, [query.id], this.cleanQuery(query));
    15    },
    16    handleResponse: function(status, headers, payload, requestData) {
    17      let response = payload;
    18      const method = requestData.method;
    19      if (status === HTTP_OK) {
    20        const url = this.parseURL(requestData.url);
    21        switch (true) {
    22          case this.isQueryRecord(url, method):
    23            response = this.handleSingleResponse(url, { Nodes: response }, PRIMARY_KEY, SLUG_KEY);
    24            break;
    25          default:
    26            response = this.handleBatchResponse(url, response, PRIMARY_KEY, SLUG_KEY);
    27        }
    28      }
    29      return this._super(status, headers, response, requestData);
    30    },
    31  });