0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/core/server/models/email.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-11-06 14:44:52 +07:00
const uuid = require('uuid');
2019-11-06 12:52:58 +07:00
const ghostBookshelf = require('./base');
const Email = ghostBookshelf.Model.extend({
tableName: 'emails',
2019-11-06 14:44:52 +07:00
defaults: function defaults() {
return {
uuid: uuid.v4(),
status: 'sending'
};
},
2019-11-06 12:52:58 +07:00
emitChange: function emitChange(event, options) {
const eventToTrigger = 'email' + '.' + 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 Emails = ghostBookshelf.Collection.extend({
model: Email
});
module.exports = {
Email: ghostBookshelf.model('Email', Email),
Emails: ghostBookshelf.collection('Emails', Emails)
};