mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
3366bd1254
no-issue This is kind of copied from the session model, but simplified This will allow much easier integration with members-api
21 lines
653 B
JavaScript
21 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)
|
|
};
|