Built motion from commit 0dbf6b8.|0.0.131
[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     acceptUrl: {
21       type: DataTypes.STRING
22     },
23     rejectUrl: {
24       type: DataTypes.STRING
25     },
26     replyUrl: {
27       type: DataTypes.STRING
28     },
29     acceptMethod: {
30       type: DataTypes.ENUM('GET', 'POST')
31     },
32     rejectMethod: {
33       type: DataTypes.ENUM('GET', 'POST')
34     },
35     replyMethod: {
36       type: DataTypes.ENUM('GET', 'POST')
37     },
38     closeUrl: {
39       type: DataTypes.STRING
40     },
41     closeMethod: {
42       type: DataTypes.ENUM('GET', 'POST')
43     },
44     actions: {
45       type: DataTypes.STRING,
46       get: function() {
47         return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
48       },
49       set: function(val) {
50         return this.setDataValue('actions', JSON.stringify(val));
51       }
52     }
53   }, {
54     tableName: 'openchannel_accounts',
55     associate: function(models) {
56       OpenchannelAccount.hasMany(models.OpenchannelRoom);
57       OpenchannelAccount.hasMany(models.OpenchannelApplication, {
58         onDelete: 'cascade'
59       });
60       OpenchannelAccount.hasMany(models.OpenchannelMessage);
61       // SCOPES
62       OpenchannelAccount.hasMany(models.OpenchannelDisposition);
63       OpenchannelAccount.belongsTo(models.List);
64       OpenchannelAccount.addScope('default', {
65         include: [{
66           model: models.OpenchannelApplication,
67           include: [{
68             model: models.User,
69             attributes: ['id',
70               'name',
71               'email',
72               'internal',
73               'fullname'
74             ]
75           }, {
76             model: models.OpenchannelQueue
77           }]
78         }]
79       });
80     }
81   });
82   return OpenchannelAccount;
83 };