mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added upsert method to stripe models
no-issue This is kind of copied from the session model, but simplified This will allow much easier integration with members-api
This commit is contained in:
parent
998642eb24
commit
3366bd1254
2 changed files with 22 additions and 0 deletions
|
@ -2,6 +2,17 @@ const ghostBookshelf = require('./base');
|
|||
|
||||
const MemberStripeCustomer = ghostBookshelf.Model.extend({
|
||||
tableName: 'members_stripe_customers'
|
||||
}, {
|
||||
async upsert(data, unfilteredOptions) {
|
||||
const customerId = data.customer_id;
|
||||
const model = await this.findOne({customer_id: customerId}, unfilteredOptions);
|
||||
if (model) {
|
||||
return this.edit(data, Object.assign({}, unfilteredOptions, {
|
||||
id: model.id
|
||||
}));
|
||||
}
|
||||
return this.add(data, unfilteredOptions);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -2,6 +2,17 @@ const ghostBookshelf = require('./base');
|
|||
|
||||
const StripeCustomerSubscription = ghostBookshelf.Model.extend({
|
||||
tableName: 'stripe_customers_subscriptions'
|
||||
}, {
|
||||
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 = {
|
||||
|
|
Loading…
Add table
Reference in a new issue