2021-06-21 11:34:33 +03:00
|
|
|
import ProductBenefitItem from '../models/product-benefit-item';
|
|
|
|
import Transform from '@ember-data/serializer/transform';
|
|
|
|
import {A as emberA, isArray as isEmberArray} from '@ember/array';
|
|
|
|
|
|
|
|
export default Transform.extend({
|
|
|
|
deserialize(serialized, options) {
|
|
|
|
let benefitsItems, benefitsArray;
|
|
|
|
|
2021-06-28 12:49:54 +03:00
|
|
|
benefitsArray = serialized || [];
|
2021-06-21 11:34:33 +03:00
|
|
|
|
|
|
|
benefitsItems = benefitsArray.map((itemDetails) => {
|
|
|
|
itemDetails.isSecondary = options && options.isSecondary || false;
|
|
|
|
return ProductBenefitItem.create(itemDetails);
|
|
|
|
});
|
|
|
|
|
|
|
|
return emberA(benefitsItems);
|
|
|
|
},
|
|
|
|
|
|
|
|
serialize(deserialized) {
|
|
|
|
let benefitsArray;
|
|
|
|
|
|
|
|
if (isEmberArray(deserialized)) {
|
|
|
|
benefitsArray = deserialized.map((item) => {
|
2021-06-28 12:49:54 +03:00
|
|
|
let name = item.get('name').trim();
|
|
|
|
return {name};
|
2021-06-21 11:34:33 +03:00
|
|
|
}).compact();
|
|
|
|
} else {
|
|
|
|
benefitsArray = [];
|
|
|
|
}
|
|
|
|
|
2021-06-28 12:49:54 +03:00
|
|
|
return benefitsArray;
|
2021-06-21 11:34:33 +03:00
|
|
|
}
|
|
|
|
});
|