2019-02-21 13:10:53 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
import { PRIMARY_KEY } from 'consul-ui/models/proxy';
|
2019-03-22 17:24:40 +00:00
|
|
|
import { get, set } from '@ember/object';
|
2019-02-21 13:10:53 +00:00
|
|
|
const modelName = 'proxy';
|
|
|
|
export default RepositoryService.extend({
|
|
|
|
getModelName: function() {
|
|
|
|
return modelName;
|
|
|
|
},
|
|
|
|
getPrimaryKey: function() {
|
|
|
|
return PRIMARY_KEY;
|
|
|
|
},
|
|
|
|
findAllBySlug: function(slug, dc, configuration = {}) {
|
|
|
|
const query = {
|
|
|
|
id: slug,
|
|
|
|
dc: dc,
|
|
|
|
};
|
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
|
|
query.index = configuration.cursor;
|
|
|
|
}
|
|
|
|
return this.get('store').query(this.getModelName(), query);
|
|
|
|
},
|
|
|
|
findInstanceBySlug: function(id, slug, dc, configuration) {
|
|
|
|
return this.findAllBySlug(slug, dc, configuration).then(function(items) {
|
2019-03-22 17:24:40 +00:00
|
|
|
let res = {};
|
2019-02-21 13:10:53 +00:00
|
|
|
if (get(items, 'length') > 0) {
|
2019-03-07 10:51:39 +00:00
|
|
|
let instance = items.findBy('ServiceProxy.DestinationServiceID', id);
|
|
|
|
if (instance) {
|
2019-03-22 17:24:40 +00:00
|
|
|
res = instance;
|
|
|
|
} else {
|
|
|
|
instance = items.findBy('ServiceProxy.DestinationServiceName', slug);
|
|
|
|
if (instance) {
|
|
|
|
res = instance;
|
|
|
|
}
|
2019-02-21 13:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-22 17:24:40 +00:00
|
|
|
set(res, 'meta', get(items, 'meta'));
|
|
|
|
return res;
|
2019-02-21 13:10:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|