Added flag to create member for sending email

no-issue

This allows us to give more functionality to consumers, with a smaller
API (rather than exposing the methods for sending a magic-link email)
This commit is contained in:
Fabien O'Carroll 2019-09-26 16:53:07 +07:00
parent ff0dc6a168
commit 530390124b
2 changed files with 17 additions and 10 deletions

View File

@ -54,15 +54,6 @@ module.exports = function MembersApi({
}
}
let users = Users({
stripe,
createMember,
getMember,
updateMember,
deleteMember,
listMembers
});
const magicLinkService = new MagicLink({
transporter,
publicKey,
@ -73,6 +64,17 @@ module.exports = function MembersApi({
async function sendEmailWithMagicLink(email){
return magicLinkService.sendMagicLink({email, user: {email}});
}
const users = Users({
sendEmailWithMagicLink,
stripe,
createMember,
getMember,
updateMember,
deleteMember,
listMembers
});
async function getMemberDataFromMagicLinkToken(token){
const user = await magicLinkService.getUserFromToken(token);
const email = user && user.email;

View File

@ -1,4 +1,5 @@
module.exports = function ({
sendEmailWithMagicLink,
stripe,
createMember,
getMember,
@ -53,7 +54,11 @@ module.exports = function ({
}
async function create(data, options) {
return createMember(data, options);
const member = await createMember(data);
if (options.sendEmail) {
await sendEmailWithMagicLink(member.email, options.emailType);
}
return member;
}
return {