Updated cancelSubscription to take member id

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

Exposing this to the Admin API means that we want to be able to cancel
by id, not just email. The same pattern from editSubscription has been
used.
This commit is contained in:
Fabien O'Carroll 2021-06-10 13:27:44 +01:00
parent b2fccb2e34
commit a4dcb66080

View File

@ -437,9 +437,18 @@ module.exports = class MemberRepository {
throw new Error('Cannot update Stripe Subscription with no Stripe Connection');
}
const member = await this._Member.findOne({
email: data.email
});
let findQuery = null;
if (data.id) {
findQuery = {id: data.id};
} else if (data.email) {
findQuery = {email: data.email};
}
if (!findQuery) {
throw new Error('Cannot update Subscription without an id or email for the Member');
}
const member = await this._Member.findOne(findQuery);
const subscription = await member.related('stripeSubscriptions').query({
where: {