2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00
Ghost/core/server/models/email.js
2019-11-06 15:56:56 +07:00

46 lines
1.2 KiB
JavaScript

const uuid = require('uuid');
const ghostBookshelf = require('./base');
const Email = ghostBookshelf.Model.extend({
tableName: 'emails',
defaults: function defaults() {
return {
uuid: uuid.v4(),
status: 'sending'
};
},
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)
};