2019-11-06 10:44:52 +03:00
|
|
|
const uuid = require('uuid');
|
2019-11-06 08:52:58 +03:00
|
|
|
const ghostBookshelf = require('./base');
|
|
|
|
|
|
|
|
const Email = ghostBookshelf.Model.extend({
|
|
|
|
tableName: 'emails',
|
|
|
|
|
2019-11-06 10:44:52 +03:00
|
|
|
defaults: function defaults() {
|
|
|
|
return {
|
|
|
|
uuid: uuid.v4(),
|
2019-11-08 13:11:54 +03:00
|
|
|
status: 'pending',
|
2020-11-04 14:06:57 +03:00
|
|
|
recipient_filter: 'paid',
|
2020-11-25 20:48:24 +03:00
|
|
|
track_opens: false,
|
|
|
|
delivered_count: 0,
|
|
|
|
opened_count: 0,
|
|
|
|
failed_count: 0
|
2019-11-06 10:44:52 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2020-09-14 17:40:00 +03:00
|
|
|
post() {
|
|
|
|
return this.belongsTo('Post', 'post_id');
|
|
|
|
},
|
|
|
|
emailBatches() {
|
|
|
|
return this.hasMany('EmailBatch', 'email_id');
|
|
|
|
},
|
|
|
|
recipients() {
|
|
|
|
return this.hasMany('EmailRecipient', 'email_id');
|
|
|
|
},
|
|
|
|
|
2019-11-06 08:52:58 +03: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);
|
|
|
|
}
|
2019-11-06 12:30:11 +03:00
|
|
|
}, {
|
|
|
|
post() {
|
|
|
|
return this.belongsTo('Post');
|
|
|
|
}
|
2019-11-06 08:52:58 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const Emails = ghostBookshelf.Collection.extend({
|
|
|
|
model: Email
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Email: ghostBookshelf.model('Email', Email),
|
|
|
|
Emails: ghostBookshelf.collection('Emails', Emails)
|
|
|
|
};
|