fleet/website/api/controllers/unsubscribe-from-all-newsletters.js
Eric e381c3fe52
Website: Add Newsletter banner and NewsletterSubscription model (#7370)
* create NewsletterSubscription Model

* create subscribe and unsubcribe actions, update cloud-sdk, policies & routes

* Add newsletter email layout

* add newsletter form, update styles and page script

* Update cloud.setup.js

* lint fixes

* Update homepage.less

* unsubscribe-from-newsletter » unsubscribe-from-all-newsletters

* remove unused exit

* comment out unused attributes, update assets/.eslintrc

* update layout

* update layout after updating from main

* Update actions and routes

* lint fix
2022-09-02 17:38:34 -05:00

44 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;
}
};