2018-12-10 12:20:54 +03:00
|
|
|
const ghostBookshelf = require('./base');
|
|
|
|
|
|
|
|
const Member = ghostBookshelf.Model.extend({
|
2019-10-11 10:15:39 +03:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
2019-10-31 17:34:50 +03:00
|
|
|
onUpdated: function onUpdated(model, attrs, options) {
|
|
|
|
ghostBookshelf.Model.prototype.onUpdated.apply(this, arguments);
|
|
|
|
|
|
|
|
model.emitChange('edited', options);
|
|
|
|
},
|
|
|
|
|
2019-10-11 10:15:39 +03:00
|
|
|
onDestroyed: function onDestroyed(model, options) {
|
|
|
|
ghostBookshelf.Model.prototype.onDestroyed.apply(this, arguments);
|
|
|
|
|
|
|
|
model.emitChange('deleted', options);
|
|
|
|
}
|
2018-12-10 12:20:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const Members = ghostBookshelf.Collection.extend({
|
|
|
|
model: Member
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Member: ghostBookshelf.model('Member', Member),
|
|
|
|
Members: ghostBookshelf.collection('Members', Members)
|
|
|
|
};
|