diff --git a/ghost/members-api/lib/repositories/member/index.js b/ghost/members-api/lib/repositories/member/index.js index 98134f86c3..bd276779ab 100644 --- a/ghost/members-api/lib/repositories/member/index.js +++ b/ghost/members-api/lib/repositories/member/index.js @@ -80,6 +80,10 @@ module.exports = class MemberRepository { const memberData = _.pick(data, ['email', 'name', 'note', 'subscribed', 'geolocation', 'created_at', 'products']); + if (memberData.products && memberData.products.length > 1) { + throw new errors.BadRequestError(tpl(messages.moreThanOneProduct)); + } + const member = await this._Member.add({ ...memberData, labels @@ -128,6 +132,10 @@ module.exports = class MemberRepository { const existingProductIds = existingProducts.map(product => product.id); const incomingProductIds = data.products.map(product => product.id); + if (incomingProductIds.length > 1 && incomingProductIds.length > existingProductIds.length) { + throw new errors.BadRequestError(tpl(messages.moreThanOneProduct)); + } + const productsToAdd = _.differenceWith(incomingProductIds, existingProductIds); const productsToRemove = _.differenceWith(existingProductIds, incomingProductIds); const productsToModify = productsToAdd.concat(productsToRemove);