Built motion from commit 1038d87.|0.0.141
[motion.git] / server / models / fax_room.js
index 197bc66..a2e257e 100644 (file)
@@ -1 +1,111 @@
-var _0x59a2=["\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(_0x59a2[0]);module[_0x59a2[1]]=function(_0x7ecdx2,_0x7ecdx3){var _0x7ecdx4=_0x7ecdx2[_0x59a2[12]](_0x59a2[2],{roomId:_0x7ecdx3[_0x59a2[3]],from:_0x7ecdx3[_0x59a2[3]],status:_0x7ecdx3.ENUM(_0x59a2[4],_0x59a2[5],_0x59a2[6],_0x59a2[7],_0x59a2[8])},{tableName:_0x59a2[9],associate:function(_0x7ecdx5){_0x7ecdx4[_0x59a2[10]](_0x7ecdx5.FaxMessage);_0x7ecdx4[_0x59a2[11]](_0x7ecdx5.FaxAccount);_0x7ecdx4[_0x59a2[11]](_0x7ecdx5.User);}});return _0x7ecdx4;};
\ No newline at end of file
+/**
+ * Fax Room Model
+ */
+
+const moment = require('moment');
+
+module.exports = function(sequelize, DataTypes) {
+
+  var FaxRoom = sequelize.define('FaxRoom', {
+    contact: DataTypes.STRING,
+    account: DataTypes.STRING,
+    faxIn: {
+      type: DataTypes.INTEGER,
+      defaultValue: 0
+    },
+    faxOut: {
+      type: DataTypes.INTEGER,
+      defaultValue: 0
+    },
+    status: {
+      type: DataTypes.ENUM('NEW', 'OPEN', 'PENDING', 'CLOSED'),
+      defaultValue: 'NEW',
+      set: function(status) {
+        this.setDataValue('status', status);
+
+        switch (status) {
+          case 'NEW':
+            this.setDataValue('arrivedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
+            break;
+          case 'CLOSED':
+            this.setDataValue('closedAt', moment().format('YYYY-MM-DD HH:mm:ss'));
+            break;
+          default:
+
+        }
+      }
+    },
+    lastEvent: {
+      type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE')
+    },
+    lastEventAt: {
+      type: DataTypes.DATE
+    },
+    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);
+      }
+    },
+    waiting: {
+      type: DataTypes.BOOLEAN,
+      defaultValue: false
+    },
+    disposition: {
+      type: DataTypes.STRING
+    },
+    openReason: DataTypes.STRING,
+    arrivedAt: {
+      type: DataTypes.DATE
+    },
+    closedAt: {
+      type: DataTypes.DATE
+    }
+  }, {
+    tableName: 'fax_rooms',
+    paranoid: true,
+    associate: function(models) {
+      // hasMany relations
+      FaxRoom.hasMany(models.FaxMessage);
+      FaxRoom.hasMany(models.FaxRoomStatus, {
+        plural: 'MailRoomStatuses'
+      });
+      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;
+};