0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Replaced all usage of member models with members-api (#12117)

no-issue

* Added stripeSubscriptions relation to member model

This allows us to fetch the subscriptions for a member via standard
model usage, e.g. `withRelated: ['stripeSubscriptions']` rather than
offloading to loops and `decorateWithSubscriptions` functions, this is
more performant and less non-standard than the existing method.

* Updated serialize methods to match existing format

The current usage of `decorateWithSubscriptions` and the usage of
members throughout the codebase has a subscriptions array on a stripe
object on the member, this ensures that when we serialize members to
JSON that we are using the same format.

There is definitely room to change this in future, but this is an
attempt to create as few breaking changes as possible.

* Installed @tryghost/members-api@0.26.0

This includes the required API changes so that everywhere can use
members-api directly rather than models and/or helper methods
This commit is contained in:
Fabien 'egg' O'Carroll 2020-08-12 14:17:44 +01:00 committed by naz
parent c5c57cbd85
commit 39aab8ae28

View file

@ -184,7 +184,7 @@ const doImport = async ({membersBatch: members, allLabelModels, importSetLabels,
if (membersWithStripeCustomers.length) { if (membersWithStripeCustomers.length) {
await Promise.map(membersWithStripeCustomers, async (stripeMember) => { await Promise.map(membersWithStripeCustomers, async (stripeMember) => {
try { try {
await membersService.api.members.linkStripeCustomer(stripeMember.stripe_customer_id, stripeMember); await membersService.api.members.linkStripeCustomerById(stripeMember.stripe_customer_id, stripeMember.id);
} catch (error) { } catch (error) {
if (error.message.indexOf('customer') && error.code === 'resource_missing') { if (error.message.indexOf('customer') && error.code === 'resource_missing') {
error.message = `Member not imported. ${error.message}`; error.message = `Member not imported. ${error.message}`;
@ -204,7 +204,7 @@ const doImport = async ({membersBatch: members, allLabelModels, importSetLabels,
if (membersWithComplimentaryPlans.length) { if (membersWithComplimentaryPlans.length) {
await Promise.map(membersWithComplimentaryPlans, async (complimentaryMember) => { await Promise.map(membersWithComplimentaryPlans, async (complimentaryMember) => {
try { try {
await membersService.api.members.setComplimentarySubscription(complimentaryMember); await membersService.api.members.setComplimentarySubscriptionById(complimentaryMember.id);
} catch (error) { } catch (error) {
logging.error(error); logging.error(error);
invalid.errors.push(error); invalid.errors.push(error);