<commit_before>'use strict';

const NorthstarRelayBaseWorker = require('./NorthstarRelayBaseWorker');
const northstarHelper = require('./lib/helpers/northstar');

class CustomerIoEmailUnsubscribedNorthstarWorker extends NorthstarRelayBaseWorker {
  setup() {
    super.setup({
      queue: this.blink.queues.quasarCustomerIoEmailUnsubscribedQ,
      rateLimit: this.blink.config.workers.northstar.userUpdateSpeedLimit,
    });
    this.emailUnsubscribedProperty = this.blink.config.workers.northstar.emailUnsubscribed.property;
    this.emailUnsubscribedValue = this.blink.config.workers.northstar.emailUnsubscribed.value;
  }

  async consume(message) {
    const userId = message.getUserId();
    const body = {};
    body[this.emailUnsubscribedProperty] = this.emailUnsubscribedValue;
    const headers = northstarHelper.getRequestHeaders(message);

    try {
      const response = await northstarHelper.updateUserById(userId, {
        headers,
        body,
      });
      return this.handleResponse(message, response);
    } catch (error) {
      return this.logUnreachableNorthstarAndRetry(error, message);
    }
  }

  static getLogCode(name) {
    const logCodes = {
      retry: 'error_customerio_email_unsubscribed_northstar_response_not_200_retry',
      success: 'success_customerio_email_unsubscribed_northstar_response_200',
      suppress: 'success_customerio_email_unsubscribed_relay_northstar_retry_suppress',
      unprocessable: 'error_customerio_email_unsubscribed_northstar_response_422',
    };
    return logCodes[name];
  }
}

module.exports = CustomerIoEmailUnsubscribedNorthstarWorker;
<commit_msg>Combining body object assignment and property destructuring per https://github.com/DoSomething/blink/pull/221#discussion_r213365569<commit_after>'use strict';

const NorthstarRelayBaseWorker = require('./NorthstarRelayBaseWorker');
const northstarHelper = require('./lib/helpers/northstar');

const logCodes = {
  retry: 'error_customerio_email_unsubscribed_northstar_response_not_200_retry',
  success: 'success_customerio_email_unsubscribed_northstar_response_200',
  suppress: 'success_customerio_email_unsubscribed_relay_northstar_retry_suppress',
  unprocessable: 'error_customerio_email_unsubscribed_northstar_response_422',
};

class CustomerIoEmailUnsubscribedNorthstarWorker extends NorthstarRelayBaseWorker {
  setup() {
    super.setup({
      queue: this.blink.queues.quasarCustomerIoEmailUnsubscribedQ,
      rateLimit: this.blink.config.workers.northstar.userUpdateSpeedLimit,
    });
    this.emailUnsubscribedProperty = this.blink.config.workers.northstar.emailUnsubscribed.property;
    this.emailUnsubscribedValue = this.blink.config.workers.northstar.emailUnsubscribed.value;
  }

  async consume(message) {
    const userId = message.getUserId();
    const body = {
      [this.emailUnsubscribedProperty]: this.emailUnsubscribedValue,
    };
    const headers = northstarHelper.getRequestHeaders(message);

    try {
      const response = await northstarHelper.updateUserById(userId, {
        headers,
        body,
      });
      return this.handleResponse(message, response);
    } catch (error) {
      return this.logUnreachableNorthstarAndRetry(error, message);
    }
  }

  static getLogCode(name) {
    return logCodes[name];
  }
}

module.exports = CustomerIoEmailUnsubscribedNorthstarWorker;

{'fraction_non_alphanumeric': 0.0898239331542823, 'fraction_numerical': 0.008952551477170993, 'mean_word_length': 4.975044563279857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '134619', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1000, 'n_words': 138}