mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05: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
5 changed files with 27 additions and 4 deletions
|
@ -16,6 +16,7 @@ const config = require('../../../shared/config');
|
||||||
const models = require('../../models');
|
const models = require('../../models');
|
||||||
const {GhostMailer} = require('../mail');
|
const {GhostMailer} = require('../mail');
|
||||||
const jobsService = require('../jobs');
|
const jobsService = require('../jobs');
|
||||||
|
const tiersService = require('../tiers');
|
||||||
const VerificationTrigger = require('@tryghost/verification-trigger');
|
const VerificationTrigger = require('@tryghost/verification-trigger');
|
||||||
const DatabaseInfo = require('@tryghost/database-info');
|
const DatabaseInfo = require('@tryghost/database-info');
|
||||||
const settingsHelpers = require('../settings-helpers');
|
const settingsHelpers = require('../settings-helpers');
|
||||||
|
@ -51,9 +52,8 @@ const membersImporter = new MembersCSVImporter({
|
||||||
const api = await module.exports.api;
|
const api = await module.exports.api;
|
||||||
return api.members;
|
return api.members;
|
||||||
},
|
},
|
||||||
getDefaultTier: async () => {
|
getDefaultTier: () => {
|
||||||
const api = await module.exports.api;
|
return tiersService.api.readDefaultTier();
|
||||||
return api.productRepository.getDefaultProduct;
|
|
||||||
},
|
},
|
||||||
sendEmail: ghostMailer.send.bind(ghostMailer),
|
sendEmail: ghostMailer.send.bind(ghostMailer),
|
||||||
isSet: labsService.isSet.bind(labsService),
|
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 {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.getMembersRepository - member model access instance for data access and manipulation
|
* @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 {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 {({job, offloaded}) => void} options.addJob - Method registering an async job
|
* @param {({job, offloaded}) => void} options.addJob - Method registering an async job
|
||||||
|
|
|
@ -17,6 +17,8 @@ class InMemoryTierRepository {
|
||||||
toPrimitive(tier) {
|
toPrimitive(tier) {
|
||||||
return {
|
return {
|
||||||
...tier,
|
...tier,
|
||||||
|
active: (tier.status === 'active'),
|
||||||
|
type: tier.type,
|
||||||
id: tier.id.toHexString()
|
id: tier.id.toHexString()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,21 @@ module.exports = class TiersAPI {
|
||||||
return tier;
|
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 {string} id
|
||||||
* @param {object} data
|
* @param {object} data
|
||||||
|
|
|
@ -72,4 +72,10 @@ describe('TiersAPI', function () {
|
||||||
assert(page.data.length === 2);
|
assert(page.data.length === 2);
|
||||||
assert(page.meta.pagination.total === 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…
Add table
Reference in a new issue