Created
September 26, 2018 15:03
-
-
Save captDaylight/a7ea3d25fd87bed573b296f878186200 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.put('/user/:refCode', function(req, res, next) { | |
if (!req.params.refCode) res.json({ result: 'error', msg: 'must send an referral code'}); | |
var newEmail = req.body.email ? req.body.email : ''; | |
mailchimp.get({ | |
path: 'lists/' + listID + '/members?unique_email_id=' + req.params.refCode, | |
}) | |
.then(function(search) { | |
const user = search.members[0]; | |
let newReferrals = user.merge_fields.REFERRALS; | |
if (user.merge_fields.REFERRALS.indexOf(newEmail) < 0) { | |
newReferrals = newReferrals === '' ? newEmail : user.merge_fields.REFERRALS + ',' + newEmail; | |
} | |
mailchimp.patch({ | |
path: 'lists/' + listID + '/members/' + md5(user.email_address.toLowerCase()), | |
body: { | |
merge_fields: { | |
REFERRALS: newReferrals, | |
} | |
} | |
}) | |
// .... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment