Built motion from commit bf7fe19.|0.0.148
[motion.git] / server / models / sms_account.js
1 'use strict';
2
3
4 module.exports = function(sequelize, DataTypes) {
5   var SmsAccount = sequelize.define('SmsAccount', {
6     name: {
7       type: DataTypes.STRING
8     },
9     description: {
10       type: DataTypes.STRING
11     },
12     type: {
13       type: DataTypes.ENUM('twilio', 'skebby')
14     },
15     smstype: {
16       type: DataTypes.ENUM('basic', 'classic', 'classic+')
17     },
18     remote: DataTypes.STRING,
19     fidelity: {
20       type: DataTypes.BOOLEAN,
21       defaultValue: false
22     },
23     timeout: {
24       type: DataTypes.INTEGER,
25       defaultValue: 0
26     },
27     phone: {
28       type: DataTypes.STRING,
29       unique: true,
30       validate: {
31         is: /^[\+]?[0-9]+$/
32       }
33     },
34     sid: {
35       type: DataTypes.STRING
36     },
37     token: {
38       type: DataTypes.STRING
39     },
40     username: {
41       type: DataTypes.STRING
42     },
43     password: {
44       type: DataTypes.STRING
45     },
46     acceptUrl: {
47       type: DataTypes.STRING
48     },
49     rejectUrl: {
50       type: DataTypes.STRING
51     },
52     acceptMethod: {
53       type: DataTypes.ENUM('GET', 'POST')
54     },
55     rejectMethod: {
56       type: DataTypes.ENUM('GET', 'POST')
57     },
58     closeUrl: {
59       type: DataTypes.STRING
60     },
61     closeMethod: {
62       type: DataTypes.ENUM('GET', 'POST')
63     },
64     actions: {
65       type: DataTypes.STRING,
66       get: function() {
67         return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
68       },
69       set: function(val) {
70         return this.setDataValue('actions', JSON.stringify(val));
71       }
72     }
73   }, {
74     tableName: 'sms_accounts',
75     associate: function(models) {
76       SmsAccount.hasMany(models.SmsRoom);
77       SmsAccount.hasMany(models.SmsApplication, {
78         onDelete: 'cascade'
79       });
80       SmsAccount.hasMany(models.SmsMessage);
81       // SCOPES
82       SmsAccount.hasMany(models.SmsDisposition);
83       SmsAccount.belongsTo(models.List);
84       SmsAccount.addScope('default', {
85         include: [{
86           model: models.SmsApplication,
87           include: [{
88             model: models.User,
89             attributes: ['id',
90               'name',
91               'email',
92               'internal',
93               'fullname'
94             ]
95           }, {
96             model: models.SmsQueue
97           }]
98         }]
99       });
100     }
101   });
102   return SmsAccount;
103 };