mirror of https://github.com/hashicorp/consul
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
import Adapter from './application';
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service';
|
|
import { OK as HTTP_OK } from 'consul-ui/utils/http/status';
|
|
export default Adapter.extend({
|
|
urlForQuery: function(query, modelName) {
|
|
return this.appendURL('internal/ui/services', [], this.cleanQuery(query));
|
|
},
|
|
urlForQueryRecord: function(query, modelName) {
|
|
if (typeof query.id === 'undefined') {
|
|
throw new Error('You must specify an id');
|
|
}
|
|
return this.appendURL('health/service', [query.id], this.cleanQuery(query));
|
|
},
|
|
handleResponse: function(status, headers, payload, requestData) {
|
|
let response = payload;
|
|
const method = requestData.method;
|
|
if (status === HTTP_OK) {
|
|
const url = this.parseURL(requestData.url);
|
|
switch (true) {
|
|
case this.isQueryRecord(url, method):
|
|
response = this.handleSingleResponse(url, { Nodes: response }, PRIMARY_KEY, SLUG_KEY);
|
|
break;
|
|
default:
|
|
response = this.handleBatchResponse(url, response, PRIMARY_KEY, SLUG_KEY);
|
|
}
|
|
}
|
|
return this._super(status, headers, response, requestData);
|
|
},
|
|
});
|