fleet/website/api/controllers/unsubscribe-from-all-newsletters.js
Eric ca73acfc3a
Website: add newsletter subscription form to homepage (#23362)
Related to: #23212

Changes:
- Added a form to the homepage for users to subscribe to the Fleet
newsletter.
- Updated the unsubscribe-from-all-newsletters action to redirect users
to the fleet homepage once they are unsubscribed from the newsletter.
- Updated the update-or-create-one-newsletter-subscription action to
create/update CRM records when users sign up for the Fleet newsletter.
2024-10-30 15:14:08 +09:00

43 lines
1.1 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Unsubscribe from all newsletters',
description: 'Sets the NewsletterSubscription record associated with the provided email address to be inactive',
inputs: {
emailAddress: {
type: 'string',
description: 'The email address associated with the newsletter subscription that will be set inactive',
required: true,
}
},
exits: {
success: {
description: 'A user has successfully unsubscribed from all newsletter emails.'
}
},
fn: async function ({emailAddress}) {
let updatedSubscription = await NewsletterSubscription.updateOne({emailAddress: emailAddress}).set({isUnsubscribedFromAll: true});
if(!updatedSubscription) { // If a subscription could not be found with the specified email address, we'll log a warning and return a 200 response.
sails.log.warn('When a user tried to unsubscribe from the Fleet newsletter, a NewsletterSubscription record for the specified email address ('+ emailAddress +') could not be found.');
}
// All done.
return this.res.redirect('/#unsubscribed');
}
};