2022-05-11 20:11:54 +03:00
|
|
|
import TierBenefitItem from '../models/tier-benefit-item';
|
2021-06-21 11:34:33 +03:00
|
|
|
import Transform from '@ember-data/serializer/transform';
|
|
|
|
import {A as emberA, isArray as isEmberArray} from '@ember/array';
|
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
export default class TierBenefits 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) => {
|
2022-05-16 21:51:49 +03:00
|
|
|
return TierBenefitItem.create({name: itemDetails});
|
2021-06-21 11:34:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
2022-05-16 21:51:49 +03:00
|
|
|
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
|
|
|
}
|