2020-10-05 17:07:35 +00:00
|
|
|
import Serializer from './application';
|
|
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/topology';
|
2020-11-12 15:40:15 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-10-05 17:07:35 +00:00
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
export default class TopologySerializer extends Serializer {
|
2020-11-12 15:40:15 +00:00
|
|
|
@service('store') store;
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
primaryKey = PRIMARY_KEY;
|
|
|
|
slugKey = SLUG_KEY;
|
|
|
|
|
|
|
|
respondForQueryRecord(respond, query) {
|
2020-11-12 15:40:15 +00:00
|
|
|
const intentionSerializer = this.store.serializerFor('intention');
|
2020-11-09 17:29:12 +00:00
|
|
|
return super.respondForQueryRecord(function(cb) {
|
2020-10-05 17:07:35 +00:00
|
|
|
return respond(function(headers, body) {
|
2020-11-12 15:40:15 +00:00
|
|
|
body.Downstreams.forEach(item => {
|
|
|
|
item.Intention.SourceName = item.Name;
|
|
|
|
item.Intention.SourceNS = item.Namespace;
|
|
|
|
item.Intention.DestinationName = query.id;
|
|
|
|
item.Intention.DestinationNS = query.ns || 'default';
|
|
|
|
intentionSerializer.ensureID(item.Intention);
|
|
|
|
});
|
|
|
|
body.Upstreams.forEach(item => {
|
|
|
|
item.Intention.SourceName = query.id;
|
|
|
|
item.Intention.SourceNS = query.ns || 'default';
|
|
|
|
item.Intention.DestinationName = item.Name;
|
|
|
|
item.Intention.DestinationNS = item.Namespace;
|
|
|
|
intentionSerializer.ensureID(item.Intention);
|
|
|
|
});
|
2020-10-05 17:07:35 +00:00
|
|
|
return cb(headers, {
|
|
|
|
...body,
|
|
|
|
[SLUG_KEY]: query.id,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, query);
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
}
|