7903512b26
* 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
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import Service, { inject as service } from '@ember/service';
|
|
import { get } from '@ember/object';
|
|
import { typeOf } from '@ember/utils';
|
|
import { PRIMARY_KEY } from 'consul-ui/models/acl';
|
|
export default Service.extend({
|
|
store: service('store'),
|
|
clone: function(item) {
|
|
return get(this, 'store').clone('acl', get(item, PRIMARY_KEY));
|
|
},
|
|
findAllByDatacenter: function(dc) {
|
|
return get(this, 'store').query('acl', {
|
|
dc: dc,
|
|
});
|
|
},
|
|
findBySlug: function(slug, dc) {
|
|
return get(this, 'store').queryRecord('acl', {
|
|
id: slug,
|
|
dc: dc,
|
|
});
|
|
},
|
|
create: function() {
|
|
return get(this, 'store').createRecord('acl');
|
|
},
|
|
persist: function(item) {
|
|
return item.save();
|
|
},
|
|
remove: function(obj) {
|
|
let item = obj;
|
|
if (typeof obj.destroyRecord === 'undefined') {
|
|
item = obj.get('data');
|
|
}
|
|
if (typeOf(item) === 'object') {
|
|
item = get(this, 'store').peekRecord('acl', item[PRIMARY_KEY]);
|
|
}
|
|
return item.destroyRecord().then(item => {
|
|
return get(this, 'store').unloadRecord(item);
|
|
});
|
|
},
|
|
invalidate: function() {
|
|
get(this, 'store').unloadAll('acl');
|
|
},
|
|
});
|