mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
55f249a328
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.
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
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)
|
|
};
|