Ghost/ghost/admin/app/transforms/product-benefits.js
Kevin Ansfield 850a223dd4 Dropped use of @classic decorator in transforms
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
2022-02-02 18:48:59 +00:00

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;
}
}