open-consul/ui-v2/app/services/services.js

29 lines
752 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 })
.then(function(items) {
return items.forEach(function(item) {
set(item, 'Datacenter', 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');
set(service, 'Nodes', nodes);
return service;
});
},
});