Ghost/core/server/models/accesstoken.js
Katharina Irrgang 8cd5d9f6fe 🎨 register events in base model (#7560)
refs #7432

- all models implemented it's own initialize fn to register events
- we can register all events in the base model
- important: we only listen on the event, if the model has defined a hook for it
- this is just a small clean up PR
- register more bookshelf events
2016-10-14 13:37:01 +01:00

29 lines
761 B
JavaScript

var ghostBookshelf = require('./base'),
Basetoken = require('./base/token'),
events = require('../events'),
Accesstoken,
Accesstokens;
Accesstoken = Basetoken.extend({
tableName: 'accesstokens',
emitChange: function emitChange(event) {
// Event named 'token' as access and refresh token will be merged in future, see #6626
events.emit('token' + '.' + event, this);
},
onCreated: function onCreated(model) {
model.emitChange('added');
}
});
Accesstokens = ghostBookshelf.Collection.extend({
model: Accesstoken
});
module.exports = {
Accesstoken: ghostBookshelf.model('Accesstoken', Accesstoken),
Accesstokens: ghostBookshelf.collection('Accesstokens', Accesstokens)
};