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:
parent
58c06bce2e
commit
83d4b5f834
1 changed files with 8 additions and 0 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue