Updated linkSubscription to handle comped status

refs https://github.com/TryGhost/Team/issues/790

When linking a subscription to a member we must also update their
status. We could be in one of many states, so we start with the initial
values of either 'free' or 'comped' based on whether the member has any
products. We then make sure to updated the status to 'paid' if we find
any active subscriptions associated with the member, otherwise we leave
it as the initial value.
This commit is contained in:
Fabien O'Carroll 2021-07-01 20:19:56 +01:00
parent 8d8d886705
commit 631e78631f

View File

@ -441,8 +441,8 @@ module.exports = class MemberRepository {
}, options); }, options);
} }
let status = 'free';
let memberProducts = (await member.related('products').fetch(options)).toJSON(); let memberProducts = (await member.related('products').fetch(options)).toJSON();
let status = memberProducts.length === 0 ? 'free' : 'comped';
if (this.isActiveSubscriptionStatus(subscription.status)) { if (this.isActiveSubscriptionStatus(subscription.status)) {
status = 'paid'; status = 'paid';
if (ghostProduct) { if (ghostProduct) {