From 99560ca90175fadb63a63bd0b85cd19091b1affa Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 20 Jul 2021 19:26:46 +0400 Subject: [PATCH] Refactored db 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 --- ghost/members-importer/lib/importer.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ghost/members-importer/lib/importer.js b/ghost/members-importer/lib/importer.js index 50644d5ffd..ca71fc616d 100644 --- a/ghost/members-importer/lib/importer.js +++ b/ghost/members-importer/lib/importer.js @@ -6,7 +6,6 @@ const errors = require('@tryghost/errors'); const tpl = require('@tryghost/tpl'); const urlUtils = require('../../../../shared/url-utils'); -const db = require('../../../data/db'); const emailTemplate = require('./email-template'); const messages = { @@ -19,18 +18,20 @@ 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 + * @param {Object} ghostMailer - An instance of GhostMailer * @param {(string) => boolean} isSet - Method checking if specific feature is enabled * @param {({name, at, job, data, offloaded}) => void} addJob - Method registering an async job - * @param {() => Object} getMembersApi + * @param {Object} knex - An instance of the Ghost Database connection */ - constructor(config, settingsCache, getMembersApi, ghostMailer, isSet, addJob) { + constructor(config, settingsCache, getMembersApi, ghostMailer, isSet, addJob, knex) { this._storagePath = config.storagePath; this._settingsCache = settingsCache; this._getMembersApi = getMembersApi; this._ghostMailer = ghostMailer; this._isSet = isSet; this._addJob = addJob; + this._knex = knex; } /** @@ -128,7 +129,7 @@ module.exports = class MembersCSVImporter { const result = await rows.reduce(async (resultPromise, row) => { const resultAccumulator = await resultPromise; - const trx = await db.knex.transaction(); + const trx = await this._knex.transaction(); const options = { transacting: trx };