2021-04-22 19:47:19 +03:00
|
|
|
import StripePrice from 'ghost-admin/models/stripe-price';
|
|
|
|
import Transform from '@ember-data/serializer/transform';
|
|
|
|
import {A as emberA, isArray as isEmberArray} from '@ember/array';
|
|
|
|
|
|
|
|
export default Transform.extend({
|
2021-06-04 10:42:52 +03:00
|
|
|
deserialize(serialized) {
|
|
|
|
if (serialized === null || serialized === undefined) {
|
|
|
|
return null;
|
|
|
|
} else if (Array.isArray(serialized)) {
|
|
|
|
const stripePrices = serialized.map(itemDetails => StripePrice.create(itemDetails));
|
2021-04-26 21:22:04 +03:00
|
|
|
|
2021-06-04 10:42:52 +03:00
|
|
|
return emberA(stripePrices);
|
|
|
|
} else {
|
|
|
|
return StripePrice.create(serialized);
|
|
|
|
}
|
2021-04-22 19:47:19 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
serialize(deserialized) {
|
|
|
|
if (isEmberArray(deserialized)) {
|
|
|
|
return deserialized.map((item) => {
|
|
|
|
return item;
|
|
|
|
}).compact();
|
|
|
|
} else {
|
2021-06-04 10:42:52 +03:00
|
|
|
return deserialized || null;
|
2021-04-22 19:47:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|