open-consul/ui-v2/app/adapters/coordinate.js
John Cowen 7903512b26
UI - Refactor Adapter.handleResponse (#4398)
* Add some tests to check the correct GET API endpoints are called

* Refactor adapters

1. Add integration tests for `urlFor...` and majority `handleResponse` methods
2. Refactor out `handleResponse` a little more into single/batch/boolean
methods
3. Move setting of the `Datacenter` property into the `handleResponse`
method, basically the same place that the uid is being set using the dc
parsed form the URL
4. Add some Errors for if you don't pass ids to certain `urlFor` methods
2018-07-30 17:55:44 +01:00

24 lines
823 B
JavaScript

import ApplicationAdapter from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/coordinate';
import { OK as HTTP_OK } from 'consul-ui/utils/http/status';
export default ApplicationAdapter.extend({
urlForQuery: function(query, modelName) {
// https://www.consul.io/api/coordinate.html#read-lan-coordinates-for-all-nodes
return this.appendURL('coordinate/nodes', [], this.cleanQuery(query));
},
isQueryRecord: function(url) {
return true;
},
handleResponse: function(status, headers, payload, requestData) {
let response = payload;
if (status === HTTP_OK) {
const url = this.parseURL(requestData.url);
response = this.handleBatchResponse(url, response, PRIMARY_KEY, SLUG_KEY);
}
return this._super(status, headers, response, requestData);
},
});