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

Handled missing data in read method bread service

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

The `get` method of the member repository will return null when no
member is found - we must ensure that we don't attempt to call toJSON!

It is also possible for a member to not have any products, in which case
we should not attempt to iterate over them, and we can return early.
This commit is contained in:
Fabien O'Carroll 2021-08-26 12:58:39 +02:00
parent 58c06bce2e
commit 83d4b5f834

View file

@ -33,8 +33,16 @@ module.exports = class MemberBREADService {
withRelated: Array.from(withRelated)
});
if (!model) {
return null;
}
const member = model.toJSON(options);
if (!member.products || !Array.isArray(member.products)) {
return member;
}
const subscriptionProducts = member.subscriptions.map(sub => sub.price.product.product_id);
for (const product of member.products) {
if (!subscriptionProducts.includes(product.id)) {