Built motion from commit 1038d87.|0.0.141
[motion.git] / server / models / sms_account.js
index f75e319..24c7782 100644 (file)
@@ -1,5 +1,6 @@
 'use strict';
 
+
 module.exports = function(sequelize, DataTypes) {
   var SmsAccount = sequelize.define('SmsAccount', {
     name: {
@@ -9,8 +10,12 @@ module.exports = function(sequelize, DataTypes) {
       type: DataTypes.STRING
     },
     type: {
-      type: DataTypes.STRING
+      type: DataTypes.ENUM('twilio', 'skebby')
+    },
+    smstype: {
+      type: DataTypes.ENUM('basic', 'classic', 'classic+')
     },
+    remote: DataTypes.STRING,
     fidelity: {
       type: DataTypes.BOOLEAN,
       defaultValue: false
@@ -20,9 +25,13 @@ module.exports = function(sequelize, DataTypes) {
       defaultValue: 0
     },
     phone: {
-      type: DataTypes.INTEGER,
-      unique: true
-
+      // type: DataTypes.INTEGER,
+      // unique: true
+      type: DataTypes.STRING,
+      unique: true,
+      validate: {
+        is: /^[0-9]+$/
+      }
     },
     sid: {
       type: DataTypes.STRING
@@ -35,15 +44,61 @@ module.exports = function(sequelize, DataTypes) {
     },
     password: {
       type: DataTypes.STRING
+    },
+    acceptUrl: {
+      type: DataTypes.STRING
+    },
+    rejectUrl: {
+      type: DataTypes.STRING
+    },
+    acceptMethod: {
+      type: DataTypes.ENUM('GET', 'POST')
+    },
+    rejectMethod: {
+      type: DataTypes.ENUM('GET', 'POST')
+    },
+    closeUrl: {
+      type: DataTypes.STRING
+    },
+    closeMethod: {
+      type: DataTypes.ENUM('GET', 'POST')
+    },
+    actions: {
+      type: DataTypes.STRING,
+      get: function() {
+        return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
+      },
+      set: function(val) {
+        return this.setDataValue('actions', JSON.stringify(val));
+      }
     }
-
   }, {
     tableName: 'sms_accounts',
     associate: function(models) {
-      // BINDING
       SmsAccount.hasMany(models.SmsRoom);
+      SmsAccount.hasMany(models.SmsApplication, {
+        onDelete: 'cascade'
+      });
       SmsAccount.hasMany(models.SmsMessage);
-
+      // SCOPES
+      SmsAccount.hasMany(models.SmsDisposition);
+      SmsAccount.belongsTo(models.List);
+      SmsAccount.addScope('default', {
+        include: [{
+          model: models.SmsApplication,
+          include: [{
+            model: models.User,
+            attributes: ['id',
+              'name',
+              'email',
+              'internal',
+              'fullname'
+            ]
+          }, {
+            model: models.SmsQueue
+          }]
+        }]
+      });
     }
   });
   return SmsAccount;