Files
threshold-ui/addons/api/addon/serializers/target.js
T

37 lines
1.1 KiB
JavaScript

import ApplicationSerializer from './application';
export default class TargetSerializer extends ApplicationSerializer {
// =methods
/**
* If `adapterOptions.hostSets` is set to an array of host set models,
* the resulting target serialization should include **only host sets**
* and the version. Normally, host sets are not serialized.
* @override
* @param {Snapshot} snapshot
* @return {object}
*/
serialize(snapshot) {
let serialized = super.serialize(...arguments);
const hostSets = snapshot?.adapterOptions?.hostSets;
if (hostSets) serialized = this.serializeWithHostSets(snapshot, hostSets);
return serialized;
}
/**
* Returns a payload containing only the host_set_ids array using host sets
* passed into the function (rather than existing host sets on the model).
* @param {Snapshot} snapshot
* @param {[HostSetModel]} hostSets
* @return {object}
*/
serializeWithHostSets(snapshot, hostSets) {
return {
version: snapshot.attr('version'),
host_set_ids: hostSets.map(({ id }) => id)
};
}
}