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

33 lines
870 B
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2020-08-21 11:53:53 -04:00
import ApplicationSerializer from './application';
2020-08-25 15:45:51 -04:00
import { underscore } from '@ember/string';
2020-08-21 11:53:53 -04:00
export default ApplicationSerializer.extend({
2020-08-25 15:45:51 -04:00
modelName: 'target',
keyForRelationshipIds(relationshipName) {
return `${this._container.inflector.singularize(
underscore(relationshipName)
)}_ids`;
},
_hashForModel(model) {
2021-03-04 15:47:38 -05:00
const json = ApplicationSerializer.prototype._hashForModel.apply(
this,
arguments
);
2020-08-25 15:45:51 -04:00
const { hostSets } = this.schema;
if (model.hostSetIds?.length) {
2021-09-22 19:15:09 -04:00
json.host_sources = model.hostSetIds.map((host_set_id) => {
const hostSet = hostSets.find(host_set_id);
const host_catalog_id = hostSet?.hostCatalog?.id;
return { id: host_set_id, host_catalog_id };
});
}
2020-08-25 15:45:51 -04:00
return json;
2021-03-04 15:47:38 -05:00
},
2020-08-21 11:53:53 -04:00
});