open-consul/ui-v2/app/services/services.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

29 lines
814 B
JavaScript

import Service, { inject as service } from '@ember/service';
import { get, set } from '@ember/object';
export default Service.extend({
store: service('store'),
findAllByDatacenter: function(dc) {
return get(this, 'store').query('service', { dc: dc });
},
findBySlug: function(slug, dc) {
return get(this, 'store')
.queryRecord('service', {
id: slug,
dc: dc,
})
.then(function(item) {
const nodes = get(item, 'Nodes');
const service = get(nodes, 'firstObject');
const tags = nodes
.reduce(function(prev, item) {
return prev.concat(get(item, 'Service.Tags') || []);
}, [])
.uniq();
set(service, 'Tags', tags);
set(service, 'Nodes', nodes);
return service;
});
},
});