2022-05-11 20:11:54 +03:00
|
|
|
import MemberTier from 'ghost-admin/models/member-tier';
|
2021-04-26 19:28:39 +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 MemberTierTransform extends Transform {
|
2021-04-26 19:28:39 +03:00
|
|
|
deserialize(serialized) {
|
|
|
|
let subscriptions, subscriptionArray;
|
|
|
|
|
|
|
|
subscriptionArray = serialized || [];
|
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
subscriptions = subscriptionArray.map(itemDetails => MemberTier.create(itemDetails));
|
2021-04-26 19:28:39 +03:00
|
|
|
|
|
|
|
return emberA(subscriptions);
|
2022-02-02 13:40:43 +03:00
|
|
|
}
|
2021-04-26 19:28:39 +03:00
|
|
|
|
|
|
|
serialize(deserialized) {
|
|
|
|
let subscriptionArray;
|
|
|
|
|
|
|
|
if (isEmberArray(deserialized)) {
|
|
|
|
subscriptionArray = deserialized.map((item) => {
|
|
|
|
return item;
|
|
|
|
}).compact();
|
|
|
|
} else {
|
|
|
|
subscriptionArray = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return subscriptionArray;
|
|
|
|
}
|
2022-02-02 13:40:43 +03:00
|
|
|
}
|