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) {
|
function unsubscribeById(req, res, next) {
|
||||||
const { unsubscribeId } = req.params;
|
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) => {
|
return User.find({ where: { unsubscribeId } }, (err, users) => {
|
||||||
if (err || !users.length) {
|
if (err || !users.length) {
|
||||||
req.flash('info', {
|
req.flash('info', {
|
||||||
@ -176,7 +182,7 @@ module.exports = function(app) {
|
|||||||
});
|
});
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
}
|
}
|
||||||
const [ user ] = users;
|
const updates = users.map(user => {
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
user.updateAttributes({
|
user.updateAttributes({
|
||||||
sendQuincyEmail: false
|
sendQuincyEmail: false
|
||||||
@ -187,7 +193,10 @@ module.exports = function(app) {
|
|||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
).then(() => {
|
);
|
||||||
|
});
|
||||||
|
return Promise.all(updates)
|
||||||
|
.then(() => {
|
||||||
req.flash('success', {
|
req.flash('success', {
|
||||||
msg: 'We\'ve successfully updated your email preferences.'
|
msg: 'We\'ve successfully updated your email preferences.'
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user