Ghost/ghost/admin/app/transforms/stripe-price.js
Rishabh 46e281241e Wired new membership tiers UI to API
refs https://github.com/TryGhost/Team/issues/712
closes https://github.com/TryGhost/Team/issues/717

The product API is updated to support `monthly/yearly_price` on each product instead of using list of stripe prices. This change updates the handling of membership settings to use the updated API instead of `stripe_prices` property.
2021-06-04 13:30:11 +05:30

28 lines
863 B
JavaScript

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({
deserialize(serialized) {
if (serialized === null || serialized === undefined) {
return null;
} else if (Array.isArray(serialized)) {
const stripePrices = serialized.map(itemDetails => StripePrice.create(itemDetails));
return emberA(stripePrices);
} else {
return StripePrice.create(serialized);
}
},
serialize(deserialized) {
if (isEmberArray(deserialized)) {
return deserialized.map((item) => {
return item;
}).compact();
} else {
return deserialized || null;
}
}
});