mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added models for stripe prices and products
refs https://github.com/TryGhost/Team/issues/586 Adds new models for stripe price and product tables
This commit is contained in:
parent
eb66c715fd
commit
5a659c9ebe
3 changed files with 77 additions and 0 deletions
|
@ -29,6 +29,8 @@ const models = [
|
|||
'mobiledoc-revision',
|
||||
'member',
|
||||
'product',
|
||||
'stripe-product',
|
||||
'stripe-price',
|
||||
'member-subscribe-event',
|
||||
'member-paid-subscription-event',
|
||||
'member-login-event',
|
||||
|
|
18
core/server/models/stripe-price.js
Normal file
18
core/server/models/stripe-price.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
const ghostBookshelf = require('./base');
|
||||
|
||||
const StripePrice = ghostBookshelf.Model.extend({
|
||||
tableName: 'stripe_prices',
|
||||
|
||||
stripeProduct() {
|
||||
return this.belongsTo('StripeProduct', 'stripe_product_id', 'stripe_product_id');
|
||||
}
|
||||
});
|
||||
|
||||
const StripePrices = ghostBookshelf.Collection.extend({
|
||||
model: StripePrice
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
StripePrice: ghostBookshelf.model('StripePrice', StripePrice),
|
||||
StripePrices: ghostBookshelf.collection('StripePrices', StripePrices)
|
||||
};
|
57
core/server/models/stripe-product.js
Normal file
57
core/server/models/stripe-product.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
const ghostBookshelf = require('./base');
|
||||
|
||||
const StripeProduct = ghostBookshelf.Model.extend({
|
||||
tableName: 'stripe_products',
|
||||
|
||||
product() {
|
||||
return this.belongsTo('Product', 'product_id', 'id');
|
||||
}
|
||||
|
||||
}, {
|
||||
async upsert(data, unfilteredOptions = {}) {
|
||||
const stripeProductId = data.stripe_product_id;
|
||||
const model = await this.findOne({stripe_product_id: stripeProductId}, unfilteredOptions);
|
||||
if (model) {
|
||||
return this.edit(data, Object.assign({}, unfilteredOptions, {
|
||||
id: model.id
|
||||
}));
|
||||
}
|
||||
return this.add(data, unfilteredOptions);
|
||||
},
|
||||
|
||||
add(data, unfilteredOptions = {}) {
|
||||
if (!unfilteredOptions.transacting) {
|
||||
return ghostBookshelf.transaction((transacting) => {
|
||||
return this.add(data, Object.assign({transacting}, unfilteredOptions));
|
||||
});
|
||||
}
|
||||
return ghostBookshelf.Model.add.call(this, data, unfilteredOptions);
|
||||
},
|
||||
|
||||
edit(data, unfilteredOptions = {}) {
|
||||
if (!unfilteredOptions.transacting) {
|
||||
return ghostBookshelf.transaction((transacting) => {
|
||||
return this.edit(data, Object.assign({transacting}, unfilteredOptions));
|
||||
});
|
||||
}
|
||||
return ghostBookshelf.Model.edit.call(this, data, unfilteredOptions);
|
||||
},
|
||||
|
||||
destroy(unfilteredOptions = {}) {
|
||||
if (!unfilteredOptions.transacting) {
|
||||
return ghostBookshelf.transaction((transacting) => {
|
||||
return this.destroy(Object.assign({transacting}, unfilteredOptions));
|
||||
});
|
||||
}
|
||||
return ghostBookshelf.Model.destroy.call(this, unfilteredOptions);
|
||||
}
|
||||
});
|
||||
|
||||
const StripeProducts = ghostBookshelf.Collection.extend({
|
||||
model: StripeProduct
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
StripeProduct: ghostBookshelf.model('StripeProduct', StripeProduct),
|
||||
StripeProducts: ghostBookshelf.collection('StripeProducts', StripeProducts)
|
||||
};
|
Loading…
Add table
Reference in a new issue