fix(user): update the unsub route
This commit is contained in:
committed by
Stuart Taylor
parent
a4a6901fc6
commit
e5de7d1837
@ -169,6 +169,12 @@ module.exports = function(app) {
|
||||
|
||||
function unsubscribeById(req, res, next) {
|
||||
const { unsubscribeId } = req.params;
|
||||
if (!unsubscribeId) {
|
||||
req.flash('info', {
|
||||
msg: 'We could not find an account to unsubscribe'
|
||||
});
|
||||
return res.redirect('/');
|
||||
}
|
||||
return User.find({ where: { unsubscribeId } }, (err, users) => {
|
||||
if (err || !users.length) {
|
||||
req.flash('info', {
|
||||
@ -176,7 +182,7 @@ module.exports = function(app) {
|
||||
});
|
||||
return res.redirect('/');
|
||||
}
|
||||
const [ user ] = users;
|
||||
const updates = users.map(user => {
|
||||
return new Promise((resolve, reject) =>
|
||||
user.updateAttributes({
|
||||
sendQuincyEmail: false
|
||||
@ -187,7 +193,10 @@ module.exports = function(app) {
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
).then(() => {
|
||||
);
|
||||
});
|
||||
return Promise.all(updates)
|
||||
.then(() => {
|
||||
req.flash('success', {
|
||||
msg: 'We\'ve successfully updated your email preferences.'
|
||||
});
|
||||
|
Reference in New Issue
Block a user