Built motion from commit 5b01f56.|0.0.106
[motion.git] / server / models / fax_room.js
index 03495d3..26618af 100644 (file)
@@ -1 +1,69 @@
-var _0xb1be=["\x63\x72\x79\x70\x74\x6F","\x65\x78\x70\x6F\x72\x74\x73","\x46\x61\x78\x52\x6F\x6F\x6D","\x53\x54\x52\x49\x4E\x47","\x4E\x45\x57","\x4F\x50\x45\x4E","\x50\x45\x4E\x44\x49\x4E\x47","\x53\x4F\x4C\x56\x45\x44","\x43\x4C\x4F\x53\x45\x44","\x66\x61\x78\x5F\x72\x6F\x6F\x6D\x73","\x68\x61\x73\x4D\x61\x6E\x79","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F","\x64\x65\x66\x69\x6E\x65"];var crypto=require(_0xb1be[0]);module[_0xb1be[1]]=function(_0xf71ex2,_0xf71ex3){var _0xf71ex4=_0xf71ex2[_0xb1be[12]](_0xb1be[2],{roomId:_0xf71ex3[_0xb1be[3]],from:_0xf71ex3[_0xb1be[3]],status:_0xf71ex3.ENUM(_0xb1be[4],_0xb1be[5],_0xb1be[6],_0xb1be[7],_0xb1be[8])},{tableName:_0xb1be[9],associate:function(_0xf71ex5){_0xf71ex4[_0xb1be[10]](_0xf71ex5.FaxMessage);_0xf71ex4[_0xb1be[11]](_0xf71ex5.FaxAccount);_0xf71ex4[_0xb1be[11]](_0xf71ex5.User)}});return _0xf71ex4}
\ No newline at end of file
+/**
+ * Fax Room Model
+ */
+
+var crypto = require('crypto');
+
+module.exports = function(sequelize, DataTypes) {
+
+  var FaxRoom = sequelize.define('FaxRoom', {
+    from: DataTypes.STRING,
+    account: DataTypes.STRING,
+    status: {
+      type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'UNMANAGED'),
+      defaultValue: 'NEW'
+    },
+    lastEvent: {
+      type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE')
+    },
+    tags: {
+      type: DataTypes.TEXT,
+      get: function() {
+        var tags;
+        if (this.getDataValue('tags')) {
+          tags = this.getDataValue('tags').split(';');
+          tags.pop();
+        } else {
+          tags = [];
+        }
+        return tags;
+      },
+      set: function(val) {
+        this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
+      }
+    },
+  }, {
+    tableName: 'fax_rooms',
+    paranoid: true,
+    associate: function(models) {
+      // hasMany relations
+      FaxRoom.hasMany(models.FaxMessage);
+      FaxRoom.belongsTo(models.FaxAccount);
+      FaxRoom.belongsToMany(models.User, {
+        through: 'user_has_fax_rooms'
+      });
+      // SCOPES
+      FaxRoom.addScope('default', {
+        order: [
+          ['createdAt', 'DESC']
+        ],
+        include: [{
+          model: models.FaxAccount
+        }, {
+          model: models.FaxMessage,
+          include: [{
+            model: models.FaxAttachment
+          }, {
+            model: models.User,
+            attributes: ['id', 'name', 'fullname', 'email']
+          }]
+        }, {
+          model: models.User,
+          attributes: ['id', 'name', 'fullname', 'email']
+        }]
+      });
+    }
+  });
+
+  return FaxRoom;
+};