mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
850a223dd4
refs https://github.com/TryGhost/Admin/pull/2242 - there was no further EmberObject specific usage to migrate for these classes so the @classic decorator is not necessary
33 lines
906 B
JavaScript
33 lines
906 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 class ProductBenefits extends Transform {
|
|
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;
|
|
}
|
|
}
|