Added added and deleted events to member model

no-issue

These can be used to trigger webhooks
This commit is contained in:
Fabien O'Carroll 2019-10-11 14:15:39 +07:00
parent df8a67a9ca
commit 94b261759e

View File

@ -1,7 +1,24 @@
const ghostBookshelf = require('./base');
const Member = ghostBookshelf.Model.extend({
tableName: 'members'
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);
},
onDestroyed: function onDestroyed(model, options) {
ghostBookshelf.Model.prototype.onDestroyed.apply(this, arguments);
model.emitChange('deleted', options);
}
});
const Members = ghostBookshelf.Collection.extend({