Built motion from commit 1038d87.|0.0.141
[motion.git] / server / models / chat_room.js
index 8e7698e..6c48356 100644 (file)
@@ -1 +1,74 @@
-var _0xae2f=["\x63\x72\x79\x70\x74\x6F","\x65\x78\x70\x6F\x72\x74\x73","\x43\x68\x61\x74\x52\x6F\x6F\x6D","\x69\x6E\x74\x65\x72\x6E\x61\x6C","\x65\x78\x74\x65\x72\x6E\x61\x6C","\x53\x54\x52\x49\x4E\x47","\x70\x65\x6E\x64\x69\x6E\x67","\x6F\x70\x65\x6E","\x63\x6C\x6F\x73\x65","\x63\x68\x61\x74\x5F\x72\x6F\x6F\x6D\x73","\x68\x61\x73\x4D\x61\x6E\x79","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F","\x55\x73\x65\x72\x48\x61\x73\x43\x68\x61\x74\x52\x6F\x6F\x6D","\x62\x65\x6C\x6F\x6E\x67\x73\x54\x6F\x4D\x61\x6E\x79","\x64\x65\x66\x69\x6E\x65"];var crypto=require(_0xae2f[0]);module[_0xae2f[1]]=function(_0xa6b3x2,_0xa6b3x3){var _0xa6b3x4=_0xa6b3x2[_0xae2f[14]](_0xae2f[2],{type:_0xa6b3x3.ENUM(_0xae2f[3],_0xae2f[4]),name:_0xa6b3x3[_0xae2f[5]],token:{type:_0xa6b3x3[_0xae2f[5]],unique:true},status:{type:_0xa6b3x3.ENUM(_0xae2f[6],_0xae2f[7],_0xae2f[8]),defaultValue:_0xae2f[6]}},{tableName:_0xae2f[9],associate:function(_0xa6b3x5){_0xa6b3x4[_0xae2f[10]](_0xa6b3x5.ChatMessage);_0xa6b3x4[_0xae2f[11]](_0xa6b3x5.ChatVisitor);_0xa6b3x4[_0xae2f[11]](_0xa6b3x5.ChatWebsite);_0xa6b3x4[_0xae2f[13]](_0xa6b3x5.User,{through:_0xa6b3x5[_0xae2f[12]]})}});return _0xa6b3x4}
\ No newline at end of file
+'use strict';
+
+module.exports = function(sequelize, DataTypes) {
+
+       var ChatRoom = sequelize.define('ChatRoom', {
+               type: DataTypes.ENUM('internal', 'external', 'group'),
+               token: {
+                       type: DataTypes.STRING,
+                       unique: 'token'
+               },
+               status: {
+                       type: DataTypes.ENUM('NEW', 'OPEN', 'CLOSED', 'ABANDON', 'UNMANAGED'),
+                       defaultValue: 'NEW'
+               },
+               rating: DataTypes.ENUM('good', 'bad'),
+               ratingMessage: DataTypes.TEXT,
+               completeReason: DataTypes.ENUM('agent', 'requester'),
+               ChatVisitorId: {
+                       type: DataTypes.INTEGER,
+                       unique: 'token'
+               },
+               waiting: {
+                       type: DataTypes.BOOLEAN,
+                       defaultValue: false
+               },
+               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);
+                       }
+               },
+               disposition: {
+                       type: DataTypes.STRING
+               },
+               openReason: DataTypes.STRING,
+               contact: DataTypes.STRING,
+               website: DataTypes.STRING
+       }, {
+               tableName: 'chat_rooms',
+               associate: function(models) {
+                       ChatRoom.hasMany(models.ChatMessage);
+                       ChatRoom.belongsTo(models.ChatVisitor);
+                       ChatRoom.belongsTo(models.ChatWebsite);
+                       ChatRoom.belongsToMany(models.User, {
+                               through: models.UserHasChatRoom
+                       });
+                       ChatRoom.addScope('online', {
+                               where: {
+                                       $and: [{
+                                               type: 'external'
+                                       }, {
+                                               $or: [{
+                                                       status: 'CLOSED'
+                                               }, {
+                                                       status: 'OPEN'
+                                               }]
+                                       }]
+                               }
+                       });
+               }
+       });
+
+       return ChatRoom;
+};