0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Refactored ghostMailer parameter

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

-  The constructor API should have as small of a surface as possible, there's no need to pass around whole ghostMailer instance
This commit is contained in:
Naz 2021-07-21 11:49:47 +04:00 committed by naz
parent 83c75a3fb4
commit 25dcfde368
2 changed files with 5 additions and 5 deletions

View file

@ -18,17 +18,17 @@ module.exports = class MembersCSVImporter {
* @param {string} options.storagePath - The path to store CSV's in before importing * @param {string} options.storagePath - The path to store CSV's in before importing
* @param {Function} options.getTimezone - function returning currently configured timezone * @param {Function} options.getTimezone - function returning currently configured timezone
* @param {() => Object} options.getMembersApi * @param {() => Object} options.getMembersApi
* @param {Object} options.ghostMailer - An instance of GhostMailer * @param {Function} options.sendEmail - function sending an email
* @param {(string) => boolean} options.isSet - Method checking if specific feature is enabled * @param {(string) => boolean} options.isSet - Method checking if specific feature is enabled
* @param {({name, at, job, data, offloaded}) => void} options.addJob - Method registering an async job * @param {({name, at, job, data, offloaded}) => void} options.addJob - Method registering an async job
* @param {Object} options.knex - An instance of the Ghost Database connection * @param {Object} options.knex - An instance of the Ghost Database connection
* @param {Function} options.urlFor - function generating urls * @param {Function} options.urlFor - function generating urls
*/ */
constructor({storagePath, getTimezone, getMembersApi, ghostMailer, isSet, addJob, knex, urlFor}) { constructor({storagePath, getTimezone, getMembersApi, sendEmail, isSet, addJob, knex, urlFor}) {
this._storagePath = storagePath; this._storagePath = storagePath;
this._getTimezone = getTimezone; this._getTimezone = getTimezone;
this._getMembersApi = getMembersApi; this._getMembersApi = getMembersApi;
this._ghostMailer = ghostMailer; this._sendEmail = sendEmail;
this._isSet = isSet; this._isSet = isSet;
this._addJob = addJob; this._addJob = addJob;
this._knex = knex; this._knex = knex;
@ -294,7 +294,7 @@ module.exports = class MembersCSVImporter {
const errorCSV = this.generateErrorCSV(result); const errorCSV = this.generateErrorCSV(result);
const emailSubject = result.imported > 0 ? 'Your member import is complete' : 'Your member import was unsuccessful'; const emailSubject = result.imported > 0 ? 'Your member import is complete' : 'Your member import was unsuccessful';
await this._ghostMailer.send({ await this._sendEmail({
to: emailRecipient, to: emailRecipient,
subject: emailSubject, subject: emailSubject,
html: emailContent, html: emailContent,

View file

@ -131,7 +131,7 @@ const membersService = {
storagePath: config.getContentPath('data'), storagePath: config.getContentPath('data'),
getTimezone: () => settingsCache.get('timezone'), getTimezone: () => settingsCache.get('timezone'),
getMembersApi: () => membersApi, getMembersApi: () => membersApi,
ghostMailer, sendEmail: ghostMailer.send.bind(ghostMailer),
isSet: labsService.isSet, isSet: labsService.isSet,
addJob: jobsService.addJob, addJob: jobsService.addJob,
knex: db.knex, knex: db.knex,