Ghost/core/server/models/accesstoken.js
kirrg001 865366c7c8 Ensured consistency for event handlers in the model layer
no issue

- the event chain works like this:
  - if a model registers an event, it get's triggered, because it's stronger than the base model
- but you have to call the base model to agree on a contract, because base model implements generic logic in event handlers
- this was inconsistently used
2019-02-07 11:02:35 +01:00

29 lines
822 B
JavaScript

const ghostBookshelf = require('./base'),
Basetoken = require('./base/token');
let Accesstoken,
Accesstokens;
Accesstoken = Basetoken.extend({
tableName: 'accesstokens',
emitChange: function emitChange(event, options) {
const eventToTrigger = 'token' + '.' + 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);
}
});
Accesstokens = ghostBookshelf.Collection.extend({
model: Accesstoken
});
module.exports = {
Accesstoken: ghostBookshelf.model('Accesstoken', Accesstoken),
Accesstokens: ghostBookshelf.collection('Accesstokens', Accesstokens)
};