b9faa7969975e7a3d4b06dc205ebf4075e8991ca
[motion.git] / server / models / openchannel_account.js
1 'use strict';
2
3 module.exports = function(sequelize, DataTypes) {
4   var OpenchannelAccount = sequelize.define('OpenchannelAccount', {
5     name: {
6       type: DataTypes.STRING
7     },
8     description: {
9       type: DataTypes.STRING
10     },
11     remote: DataTypes.STRING,
12     fidelity: {
13       type: DataTypes.BOOLEAN,
14       defaultValue: false
15     },
16     timeout: {
17       type: DataTypes.INTEGER,
18       defaultValue: 0
19     },
20     // phone: {
21     //   // type: DataTypes.INTEGER,
22     //   // unique: true
23     //   type: DataTypes.STRING,
24     //   unique: true,
25     //   validate: {
26     //     is: /^[0-9]+$/
27     //   }
28     // },
29     acceptUrl: {
30       type: DataTypes.STRING
31     },
32     rejectUrl: {
33       type: DataTypes.STRING
34     },
35     replyUrl: {
36       type: DataTypes.STRING
37     },
38     acceptMethod: {
39       type: DataTypes.ENUM('GET', 'POST')
40     },
41     rejectMethod: {
42       type: DataTypes.ENUM('GET', 'POST')
43     },
44     replyMethod: {
45       type: DataTypes.ENUM('GET', 'POST')
46     },
47     actions: {
48       type: DataTypes.STRING,
49       get: function() {
50         return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
51       },
52       set: function(val) {
53         return this.setDataValue('actions', JSON.stringify(val));
54       }
55     },
56     reply: {
57       type: DataTypes.BOOLEAN,
58       defaultValue: false
59     }
60   }, {
61     tableName: 'openchannel_accounts',
62     associate: function(models) {
63       OpenchannelAccount.hasMany(models.OpenchannelRoom);
64       OpenchannelAccount.hasMany(models.OpenchannelApplication, {
65         onDelete: 'cascade'
66       });
67       OpenchannelAccount.hasMany(models.OpenchannelMessage);
68       // SCOPES
69       OpenchannelAccount.hasMany(models.OpenchannelDisposition);
70       OpenchannelAccount.belongsTo(models.List);
71       OpenchannelAccount.addScope('default', {
72         include: [{
73           model: models.OpenchannelApplication,
74           include: [{
75             model: models.User,
76             attributes: ['id',
77               'name',
78               'email',
79               'internal',
80               'fullname'
81             ]
82           }, {
83             model: models.OpenchannelQueue
84           }]
85         }]
86       });
87     }
88   });
89   return OpenchannelAccount;
90 };