Built motion from commit 57474b6.|0.0.99
[motion.git] / server / models / mail_account.js
1 /**
2  * Chat Website Model
3  */
4
5 module.exports = function(sequelize, DataTypes) {
6
7         var MailAccount = sequelize.define('MailAccount', {
8                 description: DataTypes.STRING,
9                 name: {
10                         type: DataTypes.STRING
11                 },
12                 address: {
13                         type: DataTypes.STRING,
14                         unique: true,
15                         isEmail: true,
16                         set: function(address) {
17                                 if (address) {
18                                         this.setDataValue('address', address.toLowerCase());
19                                 }
20                         },
21                 },
22                 fidelity: {
23                         type: DataTypes.BOOLEAN,
24                         defaultValue: false
25                 },
26                 timeout: {
27                         type: DataTypes.INTEGER,
28                         defaultValue: 0
29                 }
30         }, {
31                 tableName: 'mail_accounts',
32                 associate: function(models) {
33                         // RELATIONS
34                         MailAccount.hasMany(models.MailRoom);
35                         MailAccount.hasMany(models.MailDisposition);
36                         MailAccount.hasMany(models.MailApplication);
37                         MailAccount.belongsTo(models.List);
38                         MailAccount.hasOne(models.MailServerIn, {
39                                 onDelete: 'cascade',
40                                 hooks: true
41                         });
42                         MailAccount.hasOne(models.MailServerOut, {
43                                 onDelete: 'cascade',
44                                 hooks: true
45                         });
46
47                         // SCOPES
48                         MailAccount.addScope('default', {
49                                 include: [{
50                                         model: models.MailServerIn,
51                                         attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'delete', 'filter', 'state', 'mailbox', 'connTimeout', 'authTimeout', 'keepalive', 'source']
52                                 }, {
53                                         model: models.MailServerOut,
54                                         attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'service', 'state', 'source']
55                                 }, {
56                                         model: models.MailApplication,
57                                         include: [{
58                                                 model: models.User,
59                                                 attributes: ['id',
60                                                         'name',
61                                                         'email',
62                                                         'internal',
63                                                         'fullname'
64                                                 ]
65                                         }, {
66                                                 model: models.MailQueue
67                                         }]
68                                 }]
69                         });
70                 }
71         });
72
73         return MailAccount;
74 };