189 lines
2.2 KiB
JavaScript
189 lines
2.2 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const email_logs = sequelize.define(
|
|
'email_logs',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
message_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"confirmation",
|
|
|
|
|
|
"reminder_24h",
|
|
|
|
|
|
"reminder_1h",
|
|
|
|
|
|
"followup",
|
|
|
|
|
|
"admin_notification",
|
|
|
|
|
|
"approval_request",
|
|
|
|
|
|
"approval_result",
|
|
|
|
|
|
"cancellation",
|
|
|
|
|
|
"reschedule",
|
|
|
|
|
|
"waitlist_promoted"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
to_email: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
subject: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"queued",
|
|
|
|
|
|
"sent",
|
|
|
|
|
|
"failed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
scheduled_for: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
sent_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
error_message: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
email_logs.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.email_logs.belongsTo(db.webinars, {
|
|
as: 'webinar',
|
|
foreignKey: {
|
|
name: 'webinarId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.email_logs.belongsTo(db.registrations, {
|
|
as: 'registration',
|
|
foreignKey: {
|
|
name: 'registrationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.email_logs.belongsTo(db.email_templates, {
|
|
as: 'template',
|
|
foreignKey: {
|
|
name: 'templateId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.email_logs.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.email_logs.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return email_logs;
|
|
};
|
|
|
|
|