open-consul/ui-v2/app/serializers/intention.js
John Cowen 4a76042989
ui: Correct readonly L7 Intentions API calls (#8725)
* Disable ability to select destination if not creating

* Add a LegacyID for intentions that don't have them

* Use `/exact/` endpoint for reading single intentions

* Fix up test for new API interaction

* Upgrade consul-api-double

* Comment out tests using destination for the moment

Also, removed any intention related things from the old page-navigation
tests
2020-09-24 16:07:13 +01:00

60 lines
1.5 KiB
JavaScript

import Serializer from './application';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/intention';
export default Serializer.extend({
primaryKey: PRIMARY_KEY,
slugKey: SLUG_KEY,
encoder: service('encoder'),
init: function() {
this._super();
this.uri = this.encoder.uriTag();
},
ensureID: function(item) {
if (!get(item, 'ID.length')) {
item.Legacy = false;
} else {
item.Legacy = true;
item.LegacyID = item.ID;
}
item.ID = this
.uri`${item.SourceNS}:${item.SourceName}:${item.DestinationNS}:${item.DestinationName}`;
return item;
},
respondForQuery: function(respond, query) {
return this._super(
cb =>
respond((headers, body) => {
return cb(
headers,
body.map(item => this.ensureID(item))
);
}),
query
);
},
respondForQueryRecord: function(respond, query) {
return this._super(
cb =>
respond((headers, body) => {
body = this.ensureID(body);
return cb(headers, body);
}),
query
);
},
respondForUpdateRecord: function(respond, serialized, data) {
return this._super(
cb =>
respond((headers, body) => {
body.LegacyID = body.ID;
body.ID = serialized.ID;
return cb(headers, body);
}),
serialized,
data
);
},
});