github.com/outbrain/consul@v1.4.5/ui-v2/app/services/repository.js (about)

     1  import Service, { inject as service } from '@ember/service';
     2  import { get } from '@ember/object';
     3  import { assert } from '@ember/debug';
     4  import { typeOf } from '@ember/utils';
     5  export default Service.extend({
     6    getModelName: function() {
     7      assert('RepositoryService.getModelName should be overridden', false);
     8    },
     9    getPrimaryKey: function() {
    10      assert('RepositoryService.getPrimaryKey should be overridden', false);
    11    },
    12    getSlugKey: function() {
    13      assert('RepositoryService.getSlugKey should be overridden', false);
    14    },
    15    //
    16    store: service('store'),
    17    findAllByDatacenter: function(dc) {
    18      return get(this, 'store').query(this.getModelName(), {
    19        dc: dc,
    20      });
    21    },
    22    findBySlug: function(slug, dc) {
    23      return get(this, 'store').queryRecord(this.getModelName(), {
    24        id: slug,
    25        dc: dc,
    26      });
    27    },
    28    create: function(obj) {
    29      // TODO: This should probably return a Promise
    30      return get(this, 'store').createRecord(this.getModelName(), obj);
    31    },
    32    persist: function(item) {
    33      return item.save();
    34    },
    35    remove: function(obj) {
    36      let item = obj;
    37      if (typeof obj.destroyRecord === 'undefined') {
    38        item = obj.get('data');
    39      }
    40      if (typeOf(item) === 'object') {
    41        item = get(this, 'store').peekRecord(this.getModelName(), item[this.getPrimaryKey()]);
    42      }
    43      return item.destroyRecord().then(item => {
    44        return get(this, 'store').unloadRecord(item);
    45      });
    46    },
    47    invalidate: function() {
    48      get(this, 'store').unloadAll(this.getModelName());
    49    },
    50  });