Ghost/core/server/services/members/utils.js
Fabien 'egg' O'Carroll 18b87d9734
Included all subscriptions in stripeSubscriptions (#12414)
refs https://github.com/TryGhost/Ghost/issues/12256

We no longer want to filter out cancelled subscriptions, so we are able
to remove the whereIn clause of the relation.

* Fixed paid flag on member
* Fixed content gating for members

Now that the subscriptions for a member include all of them, we must
explicitly check that the member has an active subscription in order to
consider them "paid"
2020-11-25 10:39:07 +00:00

18 lines
690 B
JavaScript

module.exports.formattedMemberResponse = function formattedMemberResponse(member) {
if (!member) {
return null;
}
return {
uuid: member.uuid,
email: member.email,
name: member.name,
firstname: member.name && member.name.split(' ')[0],
avatar_image: member.avatar_image,
subscribed: !!member.subscribed,
subscriptions: member.stripe ? member.stripe.subscriptions : [],
paid: member.stripe && member.stripe.subscriptions && member.stripe.subscriptions.filter((subscription) => {
return ['active', 'trialing', 'unpaid', 'past_due'].includes(subscription.status);
}).length !== 0
};
};