Ghost/core/server/models/member.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

const ghostBookshelf = require('./base');
const Member = ghostBookshelf.Model.extend({
tableName: 'members',
emitChange: function emitChange(event, options) {
const eventToTrigger = 'member' + '.' + event;
ghostBookshelf.Model.prototype.emitChange.bind(this)(this, eventToTrigger, options);
},
onCreated: function onCreated(model, attrs, options) {
ghostBookshelf.Model.prototype.onCreated.apply(this, arguments);
model.emitChange('added', options);
},
onUpdated: function onUpdated(model, attrs, options) {
ghostBookshelf.Model.prototype.onUpdated.apply(this, arguments);
model.emitChange('edited', options);
},
onDestroyed: function onDestroyed(model, options) {
ghostBookshelf.Model.prototype.onDestroyed.apply(this, arguments);
model.emitChange('deleted', options);
}
});
const Members = ghostBookshelf.Collection.extend({
model: Member
});
module.exports = {
Member: ghostBookshelf.model('Member', Member),
Members: ghostBookshelf.collection('Members', Members)
};