mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Added MemberProductEvent model & relations
refs https://github.com/TryGhost/Team/issues/873 We need a relation between members and their product events so that we can pull out the events for a particular member to generate the start date of their comped access to a product.
This commit is contained in:
parent
734f1c4422
commit
55f249a328
3 changed files with 47 additions and 0 deletions
|
@ -38,6 +38,7 @@ const models = [
|
||||||
'member-email-change-event',
|
'member-email-change-event',
|
||||||
'member-payment-event',
|
'member-payment-event',
|
||||||
'member-status-event',
|
'member-status-event',
|
||||||
|
'member-product-event',
|
||||||
'posts-meta',
|
'posts-meta',
|
||||||
'member-stripe-customer',
|
'member-stripe-customer',
|
||||||
'stripe-customer-subscription',
|
'stripe-customer-subscription',
|
||||||
|
|
41
core/server/models/member-product-event.js
Normal file
41
core/server/models/member-product-event.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
const errors = require('@tryghost/errors');
|
||||||
|
const tpl = require('@tryghost/tpl');
|
||||||
|
const ghostBookshelf = require('./base');
|
||||||
|
|
||||||
|
const messages = {
|
||||||
|
cannotPerformAction: 'Cannot {action} MemberProductEvent'
|
||||||
|
};
|
||||||
|
|
||||||
|
const MemberProductEvent = ghostBookshelf.Model.extend({
|
||||||
|
tableName: 'members_product_events',
|
||||||
|
|
||||||
|
member() {
|
||||||
|
return this.belongsTo('Member', 'member_id', 'id');
|
||||||
|
},
|
||||||
|
|
||||||
|
product() {
|
||||||
|
return this.belongsTo('Product', 'product_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}, {
|
||||||
|
async edit() {
|
||||||
|
throw new errors.IncorrectUsageError(
|
||||||
|
tpl(messages.cannotPerformAction, 'edit')
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
async destroy() {
|
||||||
|
throw new errors.IncorrectUsageError(
|
||||||
|
tpl(messages.cannotPerformAction, 'destroy')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const MemberProductEvents = ghostBookshelf.Collection.extend({
|
||||||
|
model: MemberProductEvent
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
MemberProductEvent: ghostBookshelf.model('MemberProductEvent', MemberProductEvent),
|
||||||
|
MemberProductEvents: ghostBookshelf.collection('MemberProductEvents', MemberProductEvents)
|
||||||
|
};
|
|
@ -78,6 +78,11 @@ const Member = ghostBookshelf.Model.extend({
|
||||||
email_recipients: 'email_recipients'
|
email_recipients: 'email_recipients'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
productEvents() {
|
||||||
|
return this.hasMany('MemberProductEvent', 'member_id', 'id')
|
||||||
|
.query('orderBy', 'created_at', 'DESC');
|
||||||
|
},
|
||||||
|
|
||||||
products() {
|
products() {
|
||||||
return this.belongsToMany('Product', 'members_products', 'member_id', 'product_id')
|
return this.belongsToMany('Product', 'members_products', 'member_id', 'product_id')
|
||||||
.withPivot('sort_order')
|
.withPivot('sort_order')
|
||||||
|
|
Loading…
Add table
Reference in a new issue