0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Cleaned up multipleProducts and multipleNewsletters flags

This commit is contained in:
Simon Backx 2022-05-25 10:24:56 +02:00
parent 0c83a60578
commit 14a7d1f00f
2 changed files with 8 additions and 48 deletions

View file

@ -205,14 +205,6 @@ module.exports = class MemberBREADService {
}
async add(data, options) {
if (!this.labsService.isSet('multipleProducts')) {
delete data.products;
}
if (!this.labsService.isSet('multipleNewsletters')) {
delete data.newsletters;
}
if (!this.stripeService.configured && (data.comped || data.stripe_customer_id)) {
const property = data.comped ? 'comped' : 'stripe_customer_id';
throw new errors.ValidationError({
@ -264,12 +256,6 @@ module.exports = class MemberBREADService {
throw error;
}
if (!this.labsService.isSet('multipleProducts')) {
if (data.comped) {
await this.memberRepository.setComplimentarySubscription(model, sharedOptions);
}
}
if (options.send_email) {
await this.emailService.sendEmailWithMagicLink({
email: model.get('email'), requestedType: options.email_type
@ -280,14 +266,6 @@ module.exports = class MemberBREADService {
}
async edit(data, options) {
if (!this.labsService.isSet('multipleProducts')) {
delete data.products;
}
if (!this.labsService.isSet('multipleNewsletters')) {
delete data.newsletters;
}
delete data.last_seen_at;
let model;
@ -305,20 +283,6 @@ module.exports = class MemberBREADService {
throw error;
}
const hasCompedSubscription = !!model.related('stripeSubscriptions').find((sub) => {
return sub.get('plan_nickname') === 'Complimentary' && sub.get('status') === 'active';
});
if (!this.labsService.isSet('multipleProducts')) {
if (typeof data.comped === 'boolean') {
if (data.comped && !hasCompedSubscription) {
await this.memberRepository.setComplimentarySubscription(model);
} else if (!data.comped && hasCompedSubscription) {
await this.memberRepository.cancelComplimentarySubscription(model);
}
}
}
return this.read({id: model.id}, options);
}

View file

@ -169,9 +169,7 @@ module.exports = class MembersCSVImporter {
member_id: member.id
}, options);
} else if (row.complimentary_plan) {
if (!this._isSet('multipleProducts')) {
await membersApi.members.setComplimentarySubscription(member, options);
} else if (!row.products) {
if (!row.products) {
await membersApi.members.update({
products: [{id: defaultProduct.id}]
}, {
@ -181,15 +179,13 @@ module.exports = class MembersCSVImporter {
}
}
if (this._isSet('multipleProducts')) {
if (row.products) {
await membersApi.members.update({
products: row.products
}, {
...options,
id: member.id
});
}
if (row.products) {
await membersApi.members.update({
products: row.products
}, {
...options,
id: member.id
});
}
await trx.commit();