From a1f29d8ede3471016f5d7ad1964ab92a4f12cc59 Mon Sep 17 00:00:00 2001 From: Rish Date: Tue, 19 May 2020 20:35:14 +0530 Subject: [PATCH] Updated member update method no issue - Makes passing `name` and `note` field in member update data as optional instead of making them undefined - Allows email to be updated - Adds stripe subscriptions list to updated member's response data to make update consistent with get method --- ghost/members-api/lib/users.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/ghost/members-api/lib/users.js b/ghost/members-api/lib/users.js index 09cc927cf0..cc1e87bf2e 100644 --- a/ghost/members-api/lib/users.js +++ b/ghost/members-api/lib/users.js @@ -28,19 +28,8 @@ async function getMember(data, options = {}) { return member; } -async function updateMember({name, note, subscribed, geolocation}, options = {}) { - const attrs = { - name, - note - }; - - if (subscribed !== undefined) { - attrs.subscribed = subscribed; - } - - if (geolocation !== undefined) { - attrs.geolocation = geolocation; - } +async function updateMember(data, options = {}) { + const attrs = _.pick(data, ['email', 'name', 'note', 'subscribed', 'geolocation']); const model = await Member.edit(attrs, options); @@ -136,7 +125,23 @@ module.exports = function ({ async function update(data, options) { debug(`update id:${options.id}`); - return updateMember(data, options); + const member = await updateMember(data, options); + if (!member) { + return member; + } + + try { + const subscriptions = await getStripeSubscriptions(member); + + return Object.assign(member, { + stripe: { + subscriptions + } + }); + } catch (err) { + common.logging.error(err); + return null; + } } async function list(options) {