mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
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
This commit is contained in:
parent
167811c5fd
commit
a1f29d8ede
1 changed files with 19 additions and 14 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue