Refactored Ghost mailer dependency out of MembersCSVImporter

refs https://github.com/TryGhost/Team/issues/916

-  The refactor was done follow the DI Constructor pattern and prepare module for extraction
This commit is contained in:
Naz 2021-07-20 18:42:26 +04:00
parent a2fc3dde7d
commit c7edf256f6
2 changed files with 13 additions and 5 deletions

View File

@ -4,7 +4,7 @@ const fs = require('fs-extra');
const membersCSV = require('@tryghost/members-csv');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const GhostMailer = require('../../mail').GhostMailer;
const urlUtils = require('../../../../shared/url-utils');
const db = require('../../../data/db');
const emailTemplate = require('./email-template');
@ -16,18 +16,19 @@ const messages = {
jobAlreadyComplete: 'Job is already complete.'
};
const ghostMailer = new GhostMailer();
module.exports = class MembersCSVImporter {
/**
* @param {Object} config
* @param {string} config.storagePath - The path to store CSV's in before importing
* @param {Object} settingsCache - An instance of the Ghost Settings Cache
* @param {Object} ghostMailer - An instance of GhostMailer
* @param {() => Object} getMembersApi
*/
constructor(config, settingsCache, getMembersApi) {
constructor(config, settingsCache, getMembersApi, ghostMailer) {
this._storagePath = config.storagePath;
this._settingsCache = settingsCache;
this._getMembersApi = getMembersApi;
this._ghostMailer = ghostMailer;
}
/**
@ -289,7 +290,7 @@ module.exports = class MembersCSVImporter {
const errorCSV = this.generateErrorCSV(result);
const emailSubject = result.imported > 0 ? 'Your member import is complete' : 'Your member import was unsuccessful';
await ghostMailer.send({
await this._ghostMailer.send({
to: emailRecipient,
subject: emailSubject,
html: emailContent,

View File

@ -13,6 +13,7 @@ const settingsCache = require('../../../shared/settings-cache');
const config = require('../../../shared/config');
const ghostVersion = require('@tryghost/version');
const _ = require('lodash');
const {GhostMailer} = require('../mail');
const messages = {
noLiveKeysInDevelopment: 'Cannot use live stripe keys in development. Please restart in production mode.',
@ -23,6 +24,8 @@ const messages = {
// Bind to settings.edited to update systems based on settings changes, similar to the bridge and models/base/listeners
const events = require('../../lib/common/events');
const ghostMailer = new GhostMailer();
const membersConfig = new MembersConfigProvider({
config,
settingsCache,
@ -122,7 +125,11 @@ const membersService = {
stripeConnect: require('./stripe-connect'),
importer: new MembersCSVImporter({storagePath: config.getContentPath('data')}, settingsCache, () => membersApi),
importer: new MembersCSVImporter({
storagePath: config.getContentPath('data')},
settingsCache, () => membersApi,
ghostMailer
),
stats: new MembersStats({
db: db,