From 188423b1ed12758fa29d8ea810706e4ad5350501 Mon Sep 17 00:00:00 2001 From: Fabien egg O'Carroll Date: Wed, 1 Dec 2021 10:45:50 +0200 Subject: [PATCH] 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. --- ghost/members-api/lib/services/member-bread.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ghost/members-api/lib/services/member-bread.js b/ghost/members-api/lib/services/member-bread.js index bcf6f30a57..5a9ad0a2df 100644 --- a/ghost/members-api/lib/services/member-bread.js +++ b/ghost/members-api/lib/services/member-bread.js @@ -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;