e75f08f6356008be51ffbd08a8936dd568ba86f5
[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.belongsTo(models.List);
35                         MailAccount.belongsTo(models.Template);
36                         MailAccount.hasMany(models.MailRoom);
37                         MailAccount.hasMany(models.MailDisposition);
38                         MailAccount.hasMany(models.MailApplication);
39                         MailAccount.hasOne(models.MailServerIn, {
40                                 onDelete: 'cascade',
41                                 hooks: true
42                         });
43                         MailAccount.hasOne(models.MailServerOut, {
44                                 onDelete: 'cascade',
45                                 hooks: true
46                         });
47
48                         // SCOPES
49                         MailAccount.addScope('default', {
50                                 include: [{
51                                         model: models.MailServerIn,
52                                         attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'delete', 'filter', 'state', 'mailbox', 'connTimeout', 'authTimeout', 'keepalive', 'source']
53                                 }, {
54                                         model: models.MailServerOut,
55                                         attributes: ['id', 'host', 'port', 'username', 'password', 'ssl', 'service', 'state', 'source']
56                                 }, {
57                                         model: models.MailApplication,
58                                         include: [{
59                                                 model: models.User,
60                                                 attributes: ['id',
61                                                         'name',
62                                                         'email',
63                                                         'internal',
64                                                         'fullname'
65                                                 ]
66                                         }, {
67                                                 model: models.MailQueue
68                                         }]
69                                 }]
70                         });
71                 }
72         });
73
74         return MailAccount;
75 };