-var _0x5436=["\x65\x78\x70\x6F\x72\x74\x73","\x4D\x61\x69\x6C\x41\x63\x63\x6F\x75\x6E\x74","\x53\x54\x52\x49\x4E\x47","\x6D\x61\x69\x6C\x5F\x61\x63\x63\x6F\x75\x6E\x74\x73","\x68\x61\x73\x4D\x61\x6E\x79","\x63\x61\x73\x63\x61\x64\x65","\x68\x61\x73\x4F\x6E\x65","\x64\x65\x66\x69\x6E\x65"];module[_0x5436[0]]=function(_0x4161x1,_0x4161x2){var _0x4161x3=_0x4161x1[_0x5436[7]](_0x5436[1],{description:_0x4161x2[_0x5436[2]],name:{type:_0x4161x2[_0x5436[2]],unique:true},address:_0x4161x2[_0x5436[2]]},{tableName:_0x5436[3],associate:function(_0x4161x4){_0x4161x3[_0x5436[4]](_0x4161x4.MailRoom);_0x4161x3[_0x5436[4]](_0x4161x4.MailTemplate);_0x4161x3[_0x5436[4]](_0x4161x4.MailApplication);_0x4161x3[_0x5436[6]](_0x4161x4.MailServerIn,{onDelete:_0x5436[5],hooks:true});_0x4161x3[_0x5436[6]](_0x4161x4.MailServerOut,{onDelete:_0x5436[5],hooks:true});}});return _0x4161x3;};
\ No newline at end of file
+'use strict';
+
+const _ = require('lodash');
+
+module.exports = function(sequelize, DataTypes) {
+ var MailAccount = sequelize.define('MailAccount', {
+ description: DataTypes.STRING,
+ name: {
+ type: DataTypes.STRING
+ },
+ address: {
+ type: DataTypes.STRING,
+ unique: true,
+ isEmail: true,
+ set: function(address) {
+ if (address) {
+ this.setDataValue('address', address.toLowerCase());
+ }
+ }
+ },
+ fidelity: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ timeout: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ whiteLabel: {
+ type: DataTypes.STRING
+ },
+ acceptUrl: {
+ type: DataTypes.STRING
+ },
+ rejectUrl: {
+ type: DataTypes.STRING
+ },
+ acceptMethod: {
+ type: DataTypes.ENUM('GET', 'POST')
+ },
+ rejectMethod: {
+ type: DataTypes.ENUM('GET', 'POST')
+ },
+ actions: {
+ type: DataTypes.STRING,
+ get: function() {
+ return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
+ },
+ set: function(val) {
+ return this.setDataValue('actions', JSON.stringify(val));
+ }
+ },
+ closeUrl: {
+ type: DataTypes.STRING
+ },
+ closeMethod: {
+ type: DataTypes.ENUM('GET', 'POST')
+ },
+ signature: {
+ type: DataTypes.BLOB,
+ get: function() {
+ if (this.getDataValue('signature')) {
+ return _.toString(this.getDataValue('signature'));
+ }
+ }
+ },
+ custom: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ service: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ }
+ }, {
+ tableName: 'mail_accounts',
+ associate: function(models) {
+ // RELATIONS
+ MailAccount.belongsTo(models.List);
+ MailAccount.belongsTo(models.Template);
+ MailAccount.hasMany(models.MailRoom);
+ MailAccount.hasMany(models.MailDisposition);
+ MailAccount.hasMany(models.MailApplication);
+ MailAccount.hasOne(models.MailServerIn, {
+ onDelete: 'cascade',
+ hooks: true
+ });
+ MailAccount.hasOne(models.MailServerOut, {
+ onDelete: 'cascade',
+ hooks: true
+ });
+
+ // SCOPES
+ MailAccount.addScope('default', {
+ where: {
+ custom: false,
+ },
+ include: [{
+ model: models.MailServerIn,
+ attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'delete', 'filter', 'state', 'mailbox', 'connTimeout', 'authTimeout', 'keepalive', 'source', 'polling', 'pollingTimeout']
+ }, {
+ model: models.MailServerOut,
+ attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'state', 'source', 'description']
+ }, {
+ model: models.MailApplication,
+ include: [{
+ model: models.User,
+ attributes: ['id',
+ 'name',
+ 'email',
+ 'internal',
+ 'fullname'
+ ]
+ }, {
+ model: models.MailQueue
+ }]
+ }]
+ });
+ }
+ });
+
+ return MailAccount;
+};