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({
|
2021-09-17 10:11:39 +03:00
|
|
|
deserialize(serialized) {
|
2021-06-21 11:34:33 +03:00
|
|
|
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) => {
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|