mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-13 10:55:58 +03:00
Changed members-api constructor to accept Member model directly (#105)
no issue - As members have become a part of Ghost core there is no need to proxy methods like this anymore and we can allow members-api to work on the model directly - Methods come from Ghost core: https://github.com/TryGhost/Ghost/blob/cc39786/core/server/services/members/api.js#L11-L110
This commit is contained in:
parent
0149dd8f4d
commit
3060e11a4e
@ -27,11 +27,7 @@ module.exports = function MembersApi({
|
||||
},
|
||||
setMetadata,
|
||||
getMetadata,
|
||||
createMember,
|
||||
getMember,
|
||||
updateMember,
|
||||
deleteMember,
|
||||
listMembers,
|
||||
memberModel,
|
||||
logger
|
||||
}) {
|
||||
if (logger) {
|
||||
@ -89,11 +85,7 @@ module.exports = function MembersApi({
|
||||
const users = Users({
|
||||
sendEmailWithMagicLink,
|
||||
stripe,
|
||||
createMember,
|
||||
getMember,
|
||||
updateMember,
|
||||
deleteMember,
|
||||
listMembers
|
||||
memberModel
|
||||
});
|
||||
|
||||
async function getMemberDataFromMagicLinkToken(token){
|
||||
|
@ -1,13 +1,66 @@
|
||||
const debug = require('ghost-ignition').debug('users');
|
||||
|
||||
let Member;
|
||||
|
||||
async function createMember({email, name, note}, options = {}) {
|
||||
const model = await Member.add({
|
||||
email,
|
||||
name: name || null,
|
||||
note: note || null
|
||||
});
|
||||
const member = model.toJSON(options);
|
||||
return member;
|
||||
}
|
||||
|
||||
async function getMember(data, options = {}) {
|
||||
if (!data.email && !data.id && !data.uuid) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
const model = await Member.findOne(data, options);
|
||||
if (!model) {
|
||||
return null;
|
||||
}
|
||||
const member = model.toJSON(options);
|
||||
return member;
|
||||
}
|
||||
|
||||
async function updateMember({name, note, subscribed}, options = {}) {
|
||||
const attrs = {
|
||||
name: name || null,
|
||||
note: note || null
|
||||
};
|
||||
|
||||
if (subscribed !== undefined) {
|
||||
attrs.subscribed = subscribed;
|
||||
}
|
||||
|
||||
const model = await Member.edit(attrs, options);
|
||||
|
||||
const member = model.toJSON(options);
|
||||
return member;
|
||||
}
|
||||
|
||||
function deleteMember(options) {
|
||||
options = options || {};
|
||||
return Member.destroy(options);
|
||||
}
|
||||
|
||||
function listMembers(options) {
|
||||
return Member.findPage(options).then((models) => {
|
||||
return {
|
||||
members: models.data.map(model => model.toJSON(options)),
|
||||
meta: models.meta
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function ({
|
||||
sendEmailWithMagicLink,
|
||||
stripe,
|
||||
createMember,
|
||||
getMember,
|
||||
updateMember,
|
||||
listMembers,
|
||||
deleteMember
|
||||
memberModel
|
||||
}) {
|
||||
Member = memberModel;
|
||||
|
||||
async function get(data, options) {
|
||||
debug(`get id:${data.id} email:${data.email}`);
|
||||
const member = await getMember(data, options);
|
||||
|
Loading…
Reference in New Issue
Block a user