Removed archived Tiers from Portal display

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

Although we filter out archived tiers from being shown in Portal - we
must also persist this information, so that when they are unarchived,
they continue to not be shown in Portal.

Unfortunately this information is stored in a setting, rather than on
the Tier object itself, two things to consider for the future are:
1. Representing the display value on the Tier object in the API
2. Updating the DB tables to allow storing the display value on the Tier
This commit is contained in:
Fabien "egg" O'Carroll 2022-01-24 13:10:14 +02:00
parent 3eed15d21a
commit 7950de49ac
2 changed files with 29 additions and 1 deletions

View File

@ -52,7 +52,8 @@ module.exports = function MembersAPI({
OfferRedemption,
StripeProduct,
StripePrice,
Product
Product,
Settings
},
stripeAPIService,
offersAPI,
@ -71,6 +72,7 @@ module.exports = function MembersAPI({
const productRepository = new ProductRepository({
Product,
Settings,
StripeProduct,
StripePrice,
stripeAPIService

View File

@ -24,17 +24,20 @@ class ProductRepository {
/**
* @param {object} deps
* @param {any} deps.Product
* @param {any} deps.Settings
* @param {any} deps.StripeProduct
* @param {any} deps.StripePrice
* @param {import('@tryghost/members-api/lib/services/stripe-api')} deps.stripeAPIService
*/
constructor({
Product,
Settings,
StripeProduct,
StripePrice,
stripeAPIService
}) {
this._Product = Product;
this._Settings = Settings;
this._StripeProduct = StripeProduct;
this._StripePrice = StripePrice;
this._stripeAPIService = stripeAPIService;
@ -261,6 +264,29 @@ class ProductRepository {
delete productData.active;
}
if (existingProduct.get('active') === true && productData.active === false) {
const portalProductsSetting = await this._Settings.findOne({
key: 'portal_products'
}, options);
let portalProducts;
try {
portalProducts = JSON.parse(portalProductsSetting.get('value'));
} catch (err) {
portalProducts = [];
}
const updatedProducts = portalProducts.filter(product => product !== productId);
await this._Settings.edit({
key: 'portal_products',
value: JSON.stringify(updatedProducts)
}, {
...options,
id: portalProductsSetting
});
}
let product = await this._Product.edit(productData, {
...options,
id: productId