mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
5144a0e09c
no-issue Up until now we have left orphaned rows in members_stripe_* tables when a member is deleted, this updates the destroy method so that we cascade and remove any MemberStripeCustomer and StripeCustomerSubscription models related to the Member. This also adds regression tests for the new functionality as well as to confirm the existing functionality of cascading to the members_labels join table This adds the relations of Subscription->Customer & Customer->Member
25 lines
830 B
JavaScript
25 lines
830 B
JavaScript
const ghostBookshelf = require('./base');
|
|
|
|
const StripeCustomerSubscription = ghostBookshelf.Model.extend({
|
|
tableName: 'members_stripe_customers_subscriptions',
|
|
|
|
customer() {
|
|
return this.belongsTo('MemberStripeCustomer', 'customer_id', 'customer_id');
|
|
}
|
|
}, {
|
|
async upsert(data, unfilteredOptions) {
|
|
const subscriptionId = unfilteredOptions.subscription_id;
|
|
const model = await this.findOne({subscription_id: subscriptionId}, unfilteredOptions);
|
|
if (model) {
|
|
return this.edit(data, Object.assign({}, unfilteredOptions, {
|
|
id: model.id
|
|
}));
|
|
}
|
|
return this.add(data, unfilteredOptions);
|
|
}
|
|
});
|
|
|
|
module.exports = {
|
|
StripeCustomerSubscription: ghostBookshelf.model('StripeCustomerSubscription', StripeCustomerSubscription)
|
|
};
|