From 05105e1173b97e9f365710e282a938b145e755bb Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 14 Jul 2022 12:54:58 +0100 Subject: [PATCH] Updated method signatures and added JSDocs refs https://github.com/TryGhost/Team/issues/1674 - While preparing the changes had a look around and made small refactors to understand the codebase a little better. In general it's best to keep the method parameters as small and precise as possible instead of passing around a "bag-of-all-the-things" like "data" around --- ghost/members-api/lib/repositories/member.js | 26 +++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/ghost/members-api/lib/repositories/member.js b/ghost/members-api/lib/repositories/member.js index e28abb32c8..0721fe3029 100644 --- a/ghost/members-api/lib/repositories/member.js +++ b/ghost/members-api/lib/repositories/member.js @@ -686,6 +686,14 @@ module.exports = class MemberRepository { return subscription; } + /** + * + * @param {Object} data + * @param {String} data.id - member ID + * @param {Object} data.subscription + * @param {*} options + * @returns + */ async linkSubscription(data, options = {}) { if (!this._stripeAPIService.configured) { throw new errors.BadRequestError({message: tpl(messages.noStripeConnection, {action: 'link Stripe Subscription'})}); @@ -1187,6 +1195,13 @@ module.exports = class MemberRepository { }, options); } + /** + * + * @param {Object} data + * @param {String} data.id - member ID + * @param {Object} options + * @param {Object} [options.transacting] + */ async setComplimentarySubscription(data, options = {}) { if (!options.transacting) { return this._Member.transaction((transacting) => { @@ -1316,13 +1331,18 @@ module.exports = class MemberRepository { } } - async cancelComplimentarySubscription(data) { + /** + * + * @param {Object} data + * @param {String} data.id - member ID + */ + async cancelComplimentarySubscription({id}) { if (!this._stripeAPIService.configured) { throw new errors.BadRequestError({message: tpl(messages.noStripeConnection, {action: 'cancel Complimentary Subscription'})}); } const member = await this._Member.findOne({ - id: data.id + id: id }); const subscriptions = await member.related('stripeSubscriptions').fetch(); @@ -1335,7 +1355,7 @@ module.exports = class MemberRepository { ); // Only needs to update `status` await this.linkSubscription({ - id: data.id, + id: id, subscription: updatedSubscription }); } catch (err) {