Ran Comped subscriptions in transaction (#360)

no-issue

We were incorrectly mixing transactional and non-transactional
operations. An e2e test in Ghost will be merged shortly which caught
this problem.
This commit is contained in:
Fabien 'egg' O'Carroll 2022-02-01 17:05:22 +02:00 committed by GitHub
parent 40035c99bf
commit 73418e8749

View File

@ -593,7 +593,8 @@ module.exports = class MemberRepository {
if (!ghostProduct) {
let {data: pageData} = await this._productRepository.list({
limit: 1,
filter: 'type:paid'
filter: 'type:paid',
...options
});
ghostProduct = (pageData && pageData[0]) || null;
}
@ -966,7 +967,16 @@ module.exports = class MemberRepository {
}, options);
}
async setComplimentarySubscription(data, options) {
async setComplimentarySubscription(data, options = {}) {
if (!options.transacting) {
return this._Member.transaction((transacting) => {
return this.setComplimentarySubscription(data, {
...options,
transacting
});
});
}
if (!this._stripeAPIService.configured) {
throw new errors.BadRequestError(tpl(messages.noStripeConnection, {action: 'create Complimentary Subscription'}));
}