2019-09-26 08:07:52 +03:00
|
|
|
const ghostBookshelf = require('./base');
|
|
|
|
|
|
|
|
const MemberStripeCustomer = ghostBookshelf.Model.extend({
|
|
|
|
tableName: 'members_stripe_customers'
|
2019-10-08 09:10:20 +03:00
|
|
|
}, {
|
|
|
|
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);
|
|
|
|
}
|
2019-09-26 08:07:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
MemberStripeCustomer: ghostBookshelf.model('MemberStripeCustomer', MemberStripeCustomer)
|
|
|
|
};
|