mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 11:55:01 +03:00
Migrated members importer to use tiers
refs https://github.com/TryGhost/Team/issues/2077 - The "productRepository" methods have been deprecated in favor of "tiers" and "Tiers API". - The changes migrated usages of "productRepository.getDefaultProduct" to Tiers API's "readDefaultTier"
This commit is contained in:
parent
d034526fe6
commit
cdd65f25ac
@ -16,6 +16,7 @@ const config = require('../../../shared/config');
|
||||
const models = require('../../models');
|
||||
const {GhostMailer} = require('../mail');
|
||||
const jobsService = require('../jobs');
|
||||
const tiersService = require('../tiers');
|
||||
const VerificationTrigger = require('@tryghost/verification-trigger');
|
||||
const DatabaseInfo = require('@tryghost/database-info');
|
||||
const settingsHelpers = require('../settings-helpers');
|
||||
@ -51,9 +52,8 @@ const membersImporter = new MembersCSVImporter({
|
||||
const api = await module.exports.api;
|
||||
return api.members;
|
||||
},
|
||||
getDefaultTier: async () => {
|
||||
const api = await module.exports.api;
|
||||
return api.productRepository.getDefaultProduct;
|
||||
getDefaultTier: () => {
|
||||
return tiersService.api.readDefaultTier();
|
||||
},
|
||||
sendEmail: ghostMailer.send.bind(ghostMailer),
|
||||
isSet: labsService.isSet.bind(labsService),
|
||||
|
@ -30,7 +30,7 @@ module.exports = class MembersCSVImporter {
|
||||
* @param {string} options.storagePath - The path to store CSV's in before importing
|
||||
* @param {Function} options.getTimezone - function returning currently configured timezone
|
||||
* @param {() => Object} options.getMembersRepository - member model access instance for data access and manipulation
|
||||
* @param {() => Object} options.getDefaultTier - async function returning default Member Tier
|
||||
* @param {() => Promise<import('@tryghost/tiers/lib/Tier')>} options.getDefaultTier - async function returning default Member Tier
|
||||
* @param {Function} options.sendEmail - function sending an email
|
||||
* @param {(string) => boolean} options.isSet - Method checking if specific feature is enabled
|
||||
* @param {({job, offloaded}) => void} options.addJob - Method registering an async job
|
||||
|
@ -17,6 +17,8 @@ class InMemoryTierRepository {
|
||||
toPrimitive(tier) {
|
||||
return {
|
||||
...tier,
|
||||
active: (tier.status === 'active'),
|
||||
type: tier.type,
|
||||
id: tier.id.toHexString()
|
||||
};
|
||||
}
|
||||
|
@ -76,6 +76,21 @@ module.exports = class TiersAPI {
|
||||
return tier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the default tier
|
||||
* @param {object} [options]
|
||||
* @returns {Promise<Tier>}
|
||||
*/
|
||||
async readDefaultTier(options = {}) {
|
||||
const [defaultTier] = await this.#repository.getAll({
|
||||
filter: 'type:paid+active:true',
|
||||
limit: 1,
|
||||
...options
|
||||
});
|
||||
|
||||
return defaultTier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} id
|
||||
* @param {object} data
|
||||
|
@ -72,4 +72,10 @@ describe('TiersAPI', function () {
|
||||
assert(page.data.length === 2);
|
||||
assert(page.meta.pagination.total === 2);
|
||||
});
|
||||
|
||||
it('Can read a default tier', async function () {
|
||||
const defaultTier = await api.readDefaultTier();
|
||||
|
||||
assert.equal(defaultTier?.name, 'My testing Tier');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user