Skip to content

Commit

Permalink
Added createUnsubscribeUrl fn to mega
Browse files Browse the repository at this point in the history
no-issue
  • Loading branch information
allouis committed Nov 6, 2019
1 parent 4db260f commit 00db1d3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion core/server/services/mega/mega.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -151,5 +169,6 @@ function listen() {
module.exports = {
listen,
sendTestEmail,
handleUnsubscribeRequest
handleUnsubscribeRequest,
createUnsubscribeUrl
};

0 comments on commit 00db1d3

Please sign in to comment.