2019-10-07 08:03:24 +03:00
|
|
|
const ghostBookshelf = require('./base');
|
|
|
|
|
|
|
|
const StripeCustomerSubscription = ghostBookshelf.Model.extend({
|
2020-07-23 19:21:10 +03:00
|
|
|
tableName: 'members_stripe_customers_subscriptions',
|
|
|
|
|
|
|
|
customer() {
|
|
|
|
return this.belongsTo('MemberStripeCustomer', 'customer_id', 'customer_id');
|
|
|
|
}
|
2019-10-08 09:10:20 +03:00
|
|
|
}, {
|
|
|
|
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);
|
|
|
|
}
|
2019-10-07 08:03:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
StripeCustomerSubscription: ghostBookshelf.model('StripeCustomerSubscription', StripeCustomerSubscription)
|
|
|
|
};
|