Fixes: Collection creation notification email

Added: Unsubscribe option to notification email footers
Added: Two new notification types (emails not written yet)
Fixed: Validation added to notification setting events
This commit is contained in:
Tom Moor
2018-12-05 23:44:41 -08:00
parent cc8dacba32
commit 9ca0038d39
8 changed files with 131 additions and 17 deletions

View File

@ -1,4 +1,5 @@
// @flow
import crypto from 'crypto';
import { DataTypes, sequelize } from '../sequelize';
const NotificationSetting = sequelize.define(
@ -11,14 +12,42 @@ const NotificationSetting = sequelize.define(
},
event: {
type: DataTypes.STRING,
validate: {
isIn: [
[
'documents.publish',
'documents.update',
'collections.create',
'emails.onboarding',
'emails.features',
],
],
},
},
},
{
timestamps: true,
updatedAt: false,
getterMethods: {
unsubscribeUrl: function() {
const token = NotificationSetting.getUnsubscribeToken(this.userId);
return `${process.env.URL}/api/notificationSettings.unsubscribe?token=${
token
}&id=${this.id}`;
},
unsubscribeToken: function() {
return NotificationSetting.getUnsubscribeToken(this.userId);
},
},
}
);
NotificationSetting.getUnsubscribeToken = userId => {
const hash = crypto.createHash('sha256');
hash.update(`${userId}-${process.env.SECRET_KEY}`);
return hash.digest('hex');
};
NotificationSetting.associate = models => {
NotificationSetting.belongsTo(models.User, {
as: 'user',