chore: use IDs rather than models

This commit is contained in:
Randall Morey committed 2020-08-26 14:03:43 -04:00
1 parent 4469ab762e
commit 819079b5f7
2 files changed
+13 -10

No files matched your search

+6 -4
View File
@@ -32,14 +32,15 @@ export default class TargetModel extends GeneratedTargetModel {
/**
* Adds host sets via the `add-host-sets` method.
* See serializer and adapter for more information.
* @param {[string]} hostSetIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
addHostSets(hostSets, options={ adapterOptions: {} }) {
addHostSets(hostSetIDs, options={ adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-host-sets',
hostSets
hostSetIDs
};
// There is no "deep merge" in ES.
// All of this nonsense is here to ensure we get
@@ -56,14 +57,15 @@ export default class TargetModel extends GeneratedTargetModel {
/**
* Delete host sets via the `delete-host-sets` method.
* See serializer and adapter for more information.
* @param {[string]} hostSetIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
deleteHostSets(hostSets, options={ adapterOptions: {} }) {
deleteHostSets(hostSetIDs, options={ adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'delete-host-sets',
hostSets
hostSetIDs
};
// There is no "deep merge" in ES.
// All of this nonsense is here to ensure we get
+7 -6
View File
@@ -14,22 +14,23 @@ export default class TargetSerializer extends ApplicationSerializer {
*/
serialize(snapshot) {
let serialized = super.serialize(...arguments);
const hostSets = snapshot?.adapterOptions?.hostSets;
if (hostSets) serialized = this.serializeWithHostSets(snapshot, hostSets);
const hostSets = snapshot?.adapterOptions?.hostSetIDs;
if (hostSetIDs) serialized =
this.serializeWithHostSets(snapshot, hostSetIDs);
return serialized;
}
/**
* Returns a payload containing only the host_set_ids array using host sets
* Returns a payload containing only the host_set_ids array using IDs
* passed into the function (rather than existing host sets on the model).
* @param {Snapshot} snapshot
* @param {[HostSetModel]} hostSets
* @param {[string]} hostSetIDs
* @return {object}
*/
serializeWithHostSets(snapshot, hostSets) {
serializeWithHostSets(snapshot, hostSetIDs) {
return {
version: snapshot.attr('version'),
host_set_ids: hostSets.map(({ id }) => id)
host_set_ids: hostSetIDs
};
}