Removed Subscriptions without Prices from BREAD API

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

It's possible to get into strange states where a subscription in Ghost
doesn't have an associated Price. This then has knock on effects because
we're dealing with data in an undefined state. Rather than add guards
against this throughout the entire stack, we stop returning it from the
BREAD API. It might be worth considering removing these subscriptions
from the response of the repository, but for now this is the most
minimal change that fixes the problem.
This commit is contained in:
Fabien egg O'Carroll 2021-12-01 10:45:50 +02:00
parent 928ff629fd
commit 188423b1ed

View File

@ -172,6 +172,7 @@ module.exports = class MemberBREADService {
const member = model.toJSON(options);
member.subscriptions = member.subscriptions.filter(sub => !!sub.price);
this.attachSubscriptionsToMember(member);
this.attachOffersToSubscriptions(member, subscriptionOffers);
@ -317,6 +318,7 @@ module.exports = class MemberBREADService {
const members = page.data.map(model => model.toJSON(options));
const data = members.map((member) => {
member.subscriptions = member.subscriptions.filter(sub => !!sub.price);
this.attachSubscriptionsToMember(member);
if (!originalWithRelated.includes('products')) {
delete member.products;