2021-06-21 11:34:33 +03:00
|
|
|
import ProductBenefitItem from '../models/product-benefit-item';
|
|
|
|
import Transform from '@ember-data/serializer/transform';
|
2022-02-02 13:40:43 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2021-06-21 11:34:33 +03:00
|
|
|
import {A as emberA, isArray as isEmberArray} from '@ember/array';
|
|
|
|
|
2022-02-02 13:40:43 +03:00
|
|
|
@classic
|
|
|
|
export default class ProductBenefits extends Transform {
|
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);
|
2022-02-02 13:40:43 +03:00
|
|
|
}
|
2021-06-21 11:34:33 +03:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2022-02-02 13:40:43 +03:00
|
|
|
}
|