mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 04:43:12 +03:00
03b37b05fb
refs https://github.com/TryGhost/Team/issues/905 - benefits were overridden with a secondary products query for segment select which did not have proper includes - fixes includes for products when fetched for member segments
33 lines
886 B
JavaScript
33 lines
886 B
JavaScript
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) {
|
|
let benefitsItems, benefitsArray;
|
|
|
|
benefitsArray = serialized || [];
|
|
|
|
benefitsItems = benefitsArray.map((itemDetails) => {
|
|
return ProductBenefitItem.create(itemDetails);
|
|
});
|
|
|
|
return emberA(benefitsItems);
|
|
},
|
|
|
|
serialize(deserialized) {
|
|
let benefitsArray;
|
|
|
|
if (isEmberArray(deserialized)) {
|
|
benefitsArray = deserialized.map((item) => {
|
|
let name = item.get('name').trim();
|
|
return {name};
|
|
}).compact();
|
|
} else {
|
|
benefitsArray = [];
|
|
}
|
|
|
|
return benefitsArray;
|
|
}
|
|
});
|