Added createUnsubscribeUrl fn to mega

no-issue
This commit is contained in:
Fabien O'Carroll 2019-11-06 17:46:30 +07:00
parent 4db260f17e
commit 00db1d385c

View File

@ -6,6 +6,7 @@ const membersService = require('../members');
const bulkEmailService = require('../bulk-email');
const models = require('../../models');
const postEmailSerializer = require('./post-email-serializer');
const urlUtils = require('../../lib/url-utils');
const sendEmail = async (post, members) => {
const emailTmpl = postEmailSerializer.serialize(post);
@ -39,6 +40,23 @@ const serialize = async (model) => {
return frame.response[docName][0];
};
/**
* createUnsubscribeUrl
*
* Takes a member and returns the url that should be used to unsubscribe
*
* @param {object} member
* @param {string} member.uuid
*/
function createUnsubscribeUrl(member) {
const siteUrl = urlUtils.getSiteUrl();
const unsubscribeUrl = new URL(siteUrl);
unsubscribeUrl.searchParams.set('action', 'unsubscribe');
unsubscribeUrl.searchParams.set('unsubscribe', member.uuid);
return unsubscribeUrl.href;
}
/**
* handleUnsubscribeRequest
*
@ -151,5 +169,6 @@ function listen() {
module.exports = {
listen,
sendTestEmail,
handleUnsubscribeRequest
handleUnsubscribeRequest,
createUnsubscribeUrl
};