Built motion from commit c56b56e.|0.0.125
[motion.git] / server / models / mail_account.js
index 3aa743d..b3c5af3 100644 (file)
@@ -1 +1,99 @@
-var _0x591d=["\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[_0x591d[0]]=function(_0xa02ax1,_0xa02ax2){var _0xa02ax3=_0xa02ax1[_0x591d[7]](_0x591d[1],{description:_0xa02ax2[_0x591d[2]],name:{type:_0xa02ax2[_0x591d[2]],unique:true},address:_0xa02ax2[_0x591d[2]]},{tableName:_0x591d[3],associate:function(_0xa02ax4){_0xa02ax3[_0x591d[4]](_0xa02ax4.MailRoom);_0xa02ax3[_0x591d[4]](_0xa02ax4.MailTemplate);_0xa02ax3[_0x591d[4]](_0xa02ax4.MailApplication);_0xa02ax3[_0x591d[6]](_0xa02ax4.MailServerIn,{onDelete:_0x591d[5],hooks:true});_0xa02ax3[_0x591d[6]](_0xa02ax4.MailServerOut,{onDelete:_0x591d[5],hooks:true});}});return _0xa02ax3;};
\ No newline at end of file
+/**
+ * Chat Website Model
+ */
+
+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));
+                       }
+               }
+       }, {
+               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', {
+                               include: [{
+                                       model: models.MailServerIn,
+                                       attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'delete', 'filter', 'state', 'mailbox', 'connTimeout', 'authTimeout', 'keepalive', 'source']
+                               }, {
+                                       model: models.MailServerOut,
+                                       attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'service', 'state', 'source']
+                               }, {
+                                       model: models.MailApplication,
+                                       include: [{
+                                               model: models.User,
+                                               attributes: ['id',
+                                                       'name',
+                                                       'email',
+                                                       'internal',
+                                                       'fullname'
+                                               ]
+                                       }, {
+                                               model: models.MailQueue
+                                       }]
+                               }]
+                       });
+               }
+       });
+
+       return MailAccount;
+};