Ghost/core/server/models/member.js
Fabien O'Carroll 354e59a795 Added defaults to member model
no-issue
2019-11-06 15:30:37 +07:00

46 lines
1.2 KiB
JavaScript

const ghostBookshelf = require('./base');
const uuid = require('uuid');
const Member = ghostBookshelf.Model.extend({
tableName: 'members',
defaults() {
return {
subscribed: true,
uuid: uuid.v4()
};
},
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)
};