2019-10-07 08:03:24 +03:00
|
|
|
const ghostBookshelf = require('./base');
|
|
|
|
|
|
|
|
const StripeCustomerSubscription = ghostBookshelf.Model.extend({
|
2019-10-09 08:37:57 +03:00
|
|
|
tableName: 'members_stripe_customers_subscriptions'
|
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)
|
|
|
|
};
|