Ghost/core/server/models/member-product-event.js
Sam Lord 18b8eddd0d Added linting for use of @tryghost/errors
refs: https://github.com/TryGhost/Toolbox/issues/147
Errors in @tryghost/errors rely on being called with an object (with a `message` member) rather than with a string.
2021-12-01 11:22:21 +00:00

42 lines
1.1 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({
message: tpl(messages.cannotPerformAction, 'edit')
});
},
async destroy() {
throw new errors.IncorrectUsageError({
message: tpl(messages.cannotPerformAction, 'destroy')
});
}
});
const MemberProductEvents = ghostBookshelf.Collection.extend({
model: MemberProductEvent
});
module.exports = {
MemberProductEvent: ghostBookshelf.model('MemberProductEvent', MemberProductEvent),
MemberProductEvents: ghostBookshelf.collection('MemberProductEvents', MemberProductEvents)
};