2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00
Ghost/core/server/models/member-stripe-customer.js
Fabien O'Carroll 3366bd1254 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
2019-10-09 16:24:51 +07:00

20 lines
653 B
JavaScript

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 = {
MemberStripeCustomer: ghostBookshelf.model('MemberStripeCustomer', MemberStripeCustomer)
};